Method references with types [Re: lambda syntax tutorial]

Fredrik Ohrstrom oehrstroem at gmail.com
Sun Aug 8 02:27:58 PDT 2010


2010/8/5 Stephen Colebourne <scolebourne at joda.org>:
> No one has yet mentioned another danger with using Foo#bar instead of
> Foo#bar(String).
>
> The former choice at this point closes off options in the future for Java.
>
> Foo#bar is the only sensible syntax for a field literal. Java can have
> both fields and methods with the same name. This has the potential to
> be a limitation to future language development.

JSR292 will never offer field literals. However JSR292 offers a quick creation
of getters and setter methods. These are pure methodhandles, ie. code.

The use cases for pure field literals are a magnitude fewer than for
method references literals.

If you want field setters and getters it is trivial to write:
Function(Person)->int getage = { p -> p.age };

Then Javac can detect that this is an "age getter" and use
MethodHandles.lookup to acquire a field getter.

When method reference literals are supported, 9999 programmers will write
save_button.onClick(this#save);
every day, and one programmer will write code for a field literal.

//Fredrik


More information about the lambda-dev mailing list