Method References

Stefan Schulz schulz at the-loom.de
Fri Feb 26 09:18:34 PST 2010


Am 26.02.2010 17:40, schrieb Joshua Bloch:
> I agree that method references would be a fine addition to the proposal, and
> I like the proposed syntax. I believe it's important that method references
> work for constructors and static methods as well as instance methods.
>
> I am very much in favor of allowing the user to omit the type information
> when it's unambiguous.  In fact, is their any reason to use "this" (as
> proposed by Fredrick):
>
>      cb = this#saveState;
>
> or could we allow:
>
>      cb = #saveState;
>
> Not only is this more succinct, but it mirrors the rules for method
> invocation, allowing "reasoning by analogy" and reducing programmer
> astonishment.

We had this proposal in FCM [1] from early beginnings, so it may be no 
wonder to see me give a big +1 ;)

As lambas do neither have a leading identifier nor would the match a 
type-only signature of a method reference, "this" would not be needed 
(at least for the compiler), but not forbidden either, as the leading 
primary might refer to another object or class.

We had them combined with literals. Especially because of field 
literals, I am in no favor of the type-less variant, as these would bar 
adding field literals (or require some other awkward syntax), which are 
also beneficial (e.g. for Beans, replacing string-based bindings).

Cheers,
Stefan

[1] http://docs.google.com/Doc?id=ddhp95vd_6hg3qhc


More information about the lambda-dev mailing list