Proposal for a simplified syntax for invoking @FunctionalInterface methods

Timothy Fagan megbeckim at gmail.com
Thu Mar 2 15:10:13 UTC 2017


I'm not sure if this is the appropriate forum, or if this idea has been
proposed elsewhere, but I'd like to suggest a simplified syntax for
invoking @FunctionalInterface methods.

The idea is that if:
*  foo is a object reference (field, local variable or parameter) whose
type is a @FunctionalInterface
*  there is a statement or expression where foo is used as if it were a
method name
*  the formal parameters of the statement or expression match the formal
parameters of the abstract method on the @FunctionalInterface
*  the formal parameters of the statement or expression do NOT match the
formal parameters of any other method in scope named foo
Then:
*  the statement or expression is compiled as an invocation of the
@FunctionalInterface abstract method on foo's type.

E.g.

Function<String, String> doubleString = s -> s + s;

// prints "hellohello"
System.out.println(*doubleString*("hello"));

-Timothy


More information about the valhalla-dev mailing list