Serialization opt-in syntax (summary)
forax at univ-mlv.fr
Tue Oct 9 07:33:33 PDT 2012
On 10/09/2012 03:40 PM, David M. Lloyd wrote:
> On 10/09/2012 01:07 AM, Remi Forax wrote:
>> We have several choices:
>> - use an annotation like @Serial, but currently there is no way o
>> attach an annotation
>> to an expression, so this was rule out.
>> - use a cast to (Foo & Serializable) but the solution to allow users
>> to use & to specify a type
>> is far from easy and require investigation and we haven't time for
>> so if no one has a better idea, this means we need a ad-hoc syntax to
>> specify that a lambda is serialize
>> (David, users want to serialize capturing lambda).
> Users also want the compiler to magically do what they mean, not what
> they say... but in the end the best thing we can do for users is make
> the rules simple and predictable.
I agree, but I think that if we have a way to tag lambda as
serializable, it's a simple and clear rule.
>> I think we have rule out to soon the fact that we also can use a
>> specific syntax, perhaps not x ~> x or
>> x -s> x (the snake arrow Josh had proposed) but a specific syntax is a
>> ad-hoc solution too.
> I don't think you are grasping how incredibly unstable it will be to
> serialize a capturing lambda, and the fact that we are more concerned
> about what (we are assuming) users (think they) want versus what we
> know will be very fragile is very worrisome to me. I am certain that
> if we allow it as-is, it *will* impact the overall perception of
> stability of Java EE, which (like it or not) relies heavily upon
> serialization (including collections).
serializing a lambda is as stable as serializing an anonymous class, so
you're right that because we don't offer a way
to have a stable name, collections implementations will not be able to
declare lambdas exactly like currently
there is no anonymous classes in the collection API, there are all
refactored as static inner classes to have a name.
It seems that Kevin and Don, our API writers are Ok with that.
> If we want to be able to support serializing capturing lambdas, they
> simply must have stable names, and their captured values must also
> have stable names; if we cannot do that then we simply cannot support it!
No, a stable name + the SAM descriptor/implementation is enough because
the captured values are like values stored in fields,
so being Serializable is enough to serialize them.
More information about the lambda-spec-observers