Method references with types [Re: lambda syntax tutorial]

Thomas Jung thomas.andreas.jung at googlemail.com
Sun Aug 8 02:53:44 PDT 2010


Hi Fredrik,

> 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.

I think you underestimate the usefulness of field literals. This "one
programmer" is the one using JPA2. If there were field literals the
APT metamodel class workaround would probably not be in JPA2.

CriteriaQuery<Order> q = cb.createQuery(Order.class);
Root<Order> order = q.from(Order.class);
Join<Order, Item> item = order.join(Order#lineItems);
q.select(order);

is much nicer than

CriteriaQuery<Order> q = cb.createQuery(Order.class);
Root<Order> order = q.from(Order.class);
Join<Order, Item> item = order.join(Order_.lineItems);
q.select(order);

which is a lot of work to implement, to get running and document
(field literal vs. there is this strange A_ class generated if you
have a working APT setup...).

Thomas



On 8 August 2010 11:27, Fredrik Ohrstrom <oehrstroem at gmail.com> wrote:
> 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