Method Pointers

Brian Goetz brian.goetz at oracle.com
Sun Feb 26 15:29:30 PST 2012


> Have you considered (I'm sure you have...) a form of requesting the
> reference to have equals semantics? Some form of method call or
> wrapper  that the user muist specifically use to get the equals or ==
> behaviour.

Yes, there are a number of possible use-site opt-ins to conversion 
options we might want to support.  One of these is giving a name to a 
lambda, which may be useful in a number of contexts.

The syntactic front-runner for this is to put a label inside the 
enclosing parens:

   (aLabel: x, y) -> x + y

but this is not yet decided.

Names are a useful part of a number of possible features, including: 
more stable serialization, better toString implementations, supporting 
nonlocal return, and others.

Another use-site opt-in would be explicit serialization support.  While 
we plan to do at least as well as inner classes -- a lambda is 
serializable if its target type is -- we'd like to do better, and 
provide a way of opting in.  This largely turns out to be a syntactic 
problem -- what is the syntactic form of the opt-in.  (Lots of 
suggestions have been made, and so far they all suck.  I will open this 
to suggestions at a future time, but until then, please hold your fire.)

The primary syntactic challenge is that because the conversion is 
invisible, there is no obvious place to hang conversion-specific 
metadata.  We don't want to abuse either the static type system, 
annotations, or "fake functions" for this purpose.  With a small number 
of conversion options we can do something ad-hoc (like the naming 
example above) but as the number of conversion options increases, this 
starts to hit the wall.



More information about the lambda-dev mailing list