Serialization opt-in syntax (again)

Brian Goetz brian.goetz at oracle.com
Mon Oct 8 09:20:31 PDT 2012


> still evaluate whether it's worth offering the (& Serializable)
> shorthand as well.  The shorthand has benefits similar to the Java 7
> "diamond", though I must concede the situation only comes up a tiny
> fraction as often.

I agree that it is worth considering such.  But, my preference here 
would be to deal with this and other sorts of verbosity in a single more 
coordinated stroke, rather than ad-hoc shorthands.  For example, at the 
EG meeting we talked about reclaiming _ as a syntactic token.  One of 
the motivations for having an "I don't want to say" token would be to 
support partial type inference.  For example, we currently support 
diamond as all-or-nothing, but something finer-grained could fit right 
into our existing machinery if it had a syntax:

   new Foo<String, _>(...)           // partial diamond

Similarly, we support inferring lambda type parameters as 
all-or-nothing, but given a syntax, could do something finer-grained:

   (String s, _ y) -> ...            // partial implicit lambda

And for target-typed lambdas, we could let inference fill in what is 
known about the target type:

   (_ & Serializable) e -> true

I think a more coordinated attack (in the future) on redundant type 
declarations would be a better choice than creating ad-hoc shorthands in 
specific situations.  (Obviously we'd have to have a long discussion on 
the actual syntax.)



More information about the lambda-spec-experts mailing list