Proposal for a simplified syntax for invoking @FunctionalInterface methods

Maurizio Cimadamore maurizio.cimadamore at oracle.com
Thu Mar 23 14:10:18 UTC 2017


Please move this discussion where it belongs, as suggested. I note that 
lambda-dev is no longer active, but compiler-dev is.

Maurizio


On 23/03/17 14:01, Christoph Engelbert wrote:
> Hey guys,
>
> Comments inline:
>
>> On 23. Mar 2017, at 06:54, Maurizio Cimadamore <maurizio.cimadamore at oracle.com> wrote:
>>
>> This is a question for lambda-dev.
>>
>> Something like this was present in the very first draft of the lambda language support [1] - syntax aside, the main issue with this avenue, is that Java has separate namespaces for methods and fields. That is, you are able to declare a field AND a method whose type is 'doubleString'. So, if you start treating fields in a more method-y way, the namespace issue might pop up, and ambiguities might ensue.
> But wouldn’t that just be another layer of name shadowing like we already have on fields? I think it’s all about precedence of field over method or method over field. Do I miss something here (I probably do :-))?
>
>> [1] - http://cr.openjdk.java.net/~mr/lambda/straw-man/
>>
>> Maurizio
>>
>>
>> On 02/03/17 15:10, Timothy Fagan wrote:
>>> 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