Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AutoValue: Support String[] array #320

Closed
vanniktech opened this issue Apr 11, 2016 · 6 comments
Closed

AutoValue: Support String[] array #320

vanniktech opened this issue Apr 11, 2016 · 6 comments

Comments

@vanniktech
Copy link

Right now it is not supported as only primitive arrays are supported. Would love to have support for String[] aswell.

If you're also interested in this I could start an implementation.

@eamonnmcmanus
Copy link
Member

We deliberately don't support object arrays, including String[]. The reasons are here. Do you have a use case that isn't addressed well by using a List<String> instead of a String[]?

@vanniktech
Copy link
Author

Yeah I can understand those reasons. Unfortunately I'm on Android where I don't have Guava Included hence I don't get ImmutableList etc and therefore String[] in this case is easier. The method List<String> myStrings() everyone can call and modify the contents of it.

If AutoValue would support String[] array and return a copy each time you call the method the class is still immutable.

@JakeWharton
Copy link
Contributor

Everyone can modify the contents of String[] as well. You can use
unmodifiableList with a defensive copy in your create method for an easy
immutable version of a list.

On Mon, Apr 11, 2016, 5:36 PM Niklas Baudy [email protected] wrote:

Yeah I can understand those reasons. Unfortunately I'm on Android where I
don't have Guava Included hence I don't get ImmutableList etc and
therefore String[] in this case is easier. The method List
myStrings() everyone can call and modify the contents of it.

If AutoValue would support String[] array and return a copy each time you
call the method the class is still immutable.


You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub
#320 (comment)

@kevinb9n
Copy link
Contributor

The point is that with an array, AutoValue would know how to just insert
'.clone()' all over the place. Unfortunately, it has been established that
automatic array cloning on get is NOT what most users want, and it was
backed out some months ago. We tried pretty hard to argue for it but our
arguments clearly didn't hold water with users.

Niklas: for what it's worth, Guava does support Android...

On Mon, Apr 11, 2016 at 2:39 PM, Jake Wharton [email protected]
wrote:

Everyone can modify the contents of String[] as well. You can use
unmodifiableList with a defensive copy in your create method for an easy
immutable version of a list.

On Mon, Apr 11, 2016, 5:36 PM Niklas Baudy [email protected]
wrote:

Yeah I can understand those reasons. Unfortunately I'm on Android where I
don't have Guava Included hence I don't get ImmutableList etc and
therefore String[] in this case is easier. The method List
myStrings() everyone can call and modify the contents of it.

If AutoValue would support String[] array and return a copy each time you
call the method the class is still immutable.


You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub
#320 (comment)


You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub
#320 (comment)

Kevin Bourrillion | Java Librarian | Google, Inc. | [email protected]

@vanniktech
Copy link
Author

To prevent anyone from modifying String[], AutoValue could use Arrays.copyOf(). Collections.unmodifiableList() would work though it kinda defeats the purpose of AutoValue in that point because you have to remember to either use ImmutableList or unmodifiableList to get immutable auto values.

For now I'll stick to unmodifiableList though String[] support would still be nice in my opinion.

@kevinb9n I know that Guava supports Android but I don't feel like adding 15k methods to my android project just to get immutable classes.

@kevinb9n
Copy link
Contributor

On Mon, Apr 11, 2016 at 2:54 PM, Niklas Baudy [email protected]
wrote:

To prevent anyone from modifying String[], AutoValue could use
Arrays.copyOf().

Same exact thing as .clone() discussed above.

Collections.unmodifiableList() would work though it kinda defeats the
purpose of AutoValue in that point because you have to remember to either
use ImmutableList or unmodifiableList to get immutable auto values.

For now I'll stick to unmodifiableList though String[] support would
still be nice in my opinion.

@kevinb9n https://github.com/kevinb9n I know that Guava supports
Android but I don't feel like adding 15k methods to my android project just
to get immutable classes.


You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub
#320 (comment)

Kevin Bourrillion | Java Librarian | Google, Inc. | [email protected]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants