Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
Function does not implement Serializable #1424
Original issue created by rpvilao on 2013-05-23 at 02:24 PM
When you perform Lists.transform and pass a Function the result is a TransformingRandomAccessList that indeed is Serializable, but Function is also a member of this class and Function is not Serializable which makes the whole object not Serializable as well.
Is this a known issue?
Original comment posted by wasserman.louis on 2013-05-24 at 06:17 AM
The solution here is to make your Function Serializable, since not all Functions are (or should be!) Serializable. (This may require an explicit named class, rather than an anonymous class, of course.)
Original comment posted by rpvilao on 2013-05-24 at 09:00 AM
Thank you for your comment. I just have a question... why isn't the function Serializable? 99% of the people using this library use an anonymous function and without any members, right? Am I missing something here?
From a user perspective I never expected that the function would be even stored in a member! What could be the harm in extending Serializable in the Function interface?
Never make abstract types Serializable! Serialization is fundamentally an implementation concern; each implementation needs to decide whether it wants to be serializable, and if it does, how it wants to be serializable (you cannot assume that default serialization is right for each case). If we make our interfaces serializable we can open security holes, not to mention that users who have all their javac warnings enabled will get a serialVersionUID warning on every single function in their entire codebase, which would be horrible.
If you find any actual Functions in our codebase that we return to you but did not make serializable, please report those.
In Java 8, serializable functions will be as easy as "transform((& Serializable) a -> a.b())". (Or at least I think that proposal carried... hmm.)