non-static method references [was: Updated State of the Lambda]

Brian Goetz brian.goetz at oracle.com
Fri Oct 15 19:52:31 PDT 2010


There are three kinds of method references:

  - Static references: #ClassName.someStaticMethod
  - Bound instance methods: #objRef.someInstanceMethod
  - Unbound instance methods: #ClassName.someInstanceMethod

Unbound instance methods are "de-curried" to take the receiver as the first 
argument.  (Which is very convenient given how they are implemented in the VM.)

These were enumerated in other places but not in the SotL draft.

The intended translation is to method handles, which avoids creating the 
intermediate desugared lambdas.

Arity is not a factor; it already works as you describe.

On 10/15/2010 7:36 PM, Per Bothner wrote:
> Section "11. Putting it together" uses the example:
>     Collections.sortBy(people, #Person.getLastName);
>
> But this is not explained in section "8. Method references",
> where the syntax #ClassName.methodName is used for references
> to static methods, while #Person.getLastName is an instance
> expression.
>
> The presumed intent is that in #ClassName.methodName
> if methodName is an nullary instance method then it is
> syntactic sugar for #{ClassName x ->  x.methodName() }.
>
> What about non-nullary instance methods?  My recommendation
> is that if methodName has parameter list (T1, ..., Tn} then
> #ClassName.methodName would be sugar for
> #{ClassName x, T1 t1, ..., Tn tn ->  x.methodName(t1, ..., tn)}.


More information about the lambda-dev mailing list