Type Annotations and Lambda

Werner Dietl wdietl at gmail.com
Tue Feb 5 15:54:43 PST 2013


Hi Maurizio,

> I am waiting on a specification clarification from Mike and/or Alex
> about METHOD_REFERENCE_RECEIVER and CONSTRUCTOR_REFERENCE_RECEIVER.
> To me these don't look like type uses, but instead only like scoping
> mechanisms, for which we don't support type annotations.
> It would be great to see a few examples of type uses for these and
> what the interpretation of type annotations should be.
>
> There are several kinds of method references - the so-called unbound kind
> has a type as a qualifier - i.e.
>
> Person::getName

In which context can I use the unbounded kind? When I try

    static Runnable returnLambda1() {
        return Test::getName;
    }

I get:

Test.java:25: error: incompatible types: invalid method reference;
non-static method getName() cannot be referenced from a static context
        return Test::getName;
               ^
1 error


> Constructor references also have a type as a qualifier:
>
> ArrayList::new

Why don't I get a warning about raw types in this example:

    static Runnable returnLambda1() {
        return ArrayList::new;
    }

Even when I compile with -Xlint:all I don't get a warning about the raw type.
This is the reason why I assumed that this is not really a type use,
but only the class name to select the constructor from that class -
not from a particular instantiation of the class.
Is the "raw type" warning missing or am I misunderstanding?


> Finally, the spec says that type annotations in the signature or body
> of a lambda expression should appear in the method that results from
> translation.
> I was hoping that this would work without any special effort. However,
> no type annotations appear in a translated method.
> Could somebody point me to the location in the code that translates a
> lambda expression into a method?
>
> This is the place:
>
> http://hg.openjdk.java.net/jdk8/jdk8/langtools/file/tip/src/share/classes/com/sun/tools/javac/comp/LambdaToMethod.java

Thanks! I'll take a look and will get back with any questions.

cu, WMD.

-- 
http://www.google.com/profiles/wdietl


More information about the type-annotations-dev mailing list