yangxu998 / guava-libraries

Automatically exported from code.google.com/p/guava-libraries
Apache License 2.0
0 stars 0 forks source link

Problems with serialization and transform... #598

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Hi,
i searched for this topic and didn't find a issue.
it is very displeasing to have the result of the transform function to be a 
internal guava class. 
The problem is that TransformingRandomAccessList contains also the Function. 

So your function also have to be serializable.

Oh, and the Frontend also have to know the Guava library to know the 
TransformingRandomAccessList.

:/. Otherwise awesome library. :)

Do you think there is a possibility to introduce a new method which returns 
just a List from the JDK (e.g. ArrayList)?

Best regards Florian

Original issue reported on code.google.com by Florian....@googlemail.com on 8 Apr 2011 at 10:07

GoogleCodeExporter commented 9 years ago
The point of methods like Lists.transform() is that they create a view of the 
collection they're given that applies the Function or Predicate only as needed. 
If you want the resulting List to be serializable, just give it a serializable 
Function. Most (all?) of the Functions that Guava provides are serializable as 
long as any user-provided objects they need to use are also.

If you want an ArrayList (a copy) rather than the live view, you can just do

  List<Foo> list = Lists.newArrayList(Lists.transform(foos, function));

Original comment by cgdec...@gmail.com on 8 Apr 2011 at 2:14

GoogleCodeExporter commented 9 years ago
This issue has been migrated to GitHub.

It can be found at https://github.com/google/guava/issues/<id>

Original comment by cgdecker@google.com on 1 Nov 2014 at 4:15

GoogleCodeExporter commented 9 years ago

Original comment by cgdecker@google.com on 3 Nov 2014 at 9:09