Method References

Fredrik Öhrström fredrik.ohrstrom at oracle.com
Fri Feb 26 01:01:26 PST 2010


Neal Gafter skrev:
> Method References (ala CfJ 0.6a) would be a valuable addition to Project
> Lambda's specification.  While the additional specification text is fairly
> small, it enable a number of useful idioms that would otherwise be quite
> verbose.
>
> The most obvious use case will be lambdas that would otherwise have to be
> written this way
>
> #(Type1 arg1, Type1 arg2, ...)(EnclosingClass.this.method(arg1, arg2, ...))
>
> because they could be written like this
>
> this#method(Type1, Type2, ...)
>
> This simplifies a common pattern seen in code today that registers
> callbacks
Yes, this is a very important and common use case. If the parentheses
and types are unnecessary, for example there is only one single method
with that particular name, please allow the reference to be created
without the types. Ie:

cb = this#saveState;

will work as expected as long as there is only a single saveState in this.

//Fredrik


More information about the lambda-dev mailing list