New JEP: Concise Method Bodies

Dan Smith daniel.smith at oracle.com
Tue Oct 9 16:31:48 UTC 2018


> On Oct 8, 2018, at 12:14 PM, Dan Smith <daniel.smith at oracle.com> wrote:
> 
> - Type-qualified method ref: if you don't pass 'this' to the method, you're throwing it away. Static utility methods could be referenced with this form. Methods of the current class/supers could be referenced, too, but 'this::foo' and 'super::foo' serve the same purpose, if we allow them.
> 
> - Expression-qualified method ref: very possibly, the expression preserves the information you need from 'this', and passing 'this' to the method would be redundant. Hard to think of examples in which a user would want 'this' to be passed as a first parameter.

Found a use case:

class Foo implements Comparable<Foo> {

    final Comparator<Foo> comp = ...;

    int compareTo(Foo arg) = comp::compare;

}

This may turn out to be a pretty important use case...

Where that leaves us is that maybe "try both" is the best strategy.



More information about the amber-spec-experts mailing list