non-static method references [was: Updated State of the Lambda]
Per Bothner
per at bothner.com
Fri Oct 15 16:36:26 PDT 2010
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)}.
--
--Per Bothner
per at bothner.com http://per.bothner.com/
More information about the lambda-dev
mailing list