Type Annotations and Lambda

Alex Buckley alex.buckley at oracle.com
Thu Feb 7 15:40:35 PST 2013


On 2/5/2013 2:19 PM, Werner Dietl wrote:
> 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.

I just spoke with Mike about this, and things are as intended.

Suppose I have an interface IntMapper<T> whose single method is "int 
map(T t)". Then I write:

   IntMapper<@Vernal Date> x = { @Vernal Date d -> BODY };
   int i = x.map(new @Vernal Date());

If I promise that BODY extracts and returns the day from d, then i will 
be 7, right? Now suppose I write:

   IntMapper<@Vernal Date> x = @Vernal Date::getDay;
   int i = x.map(new @Vernal Date());

i will also be 7 here. The method reference expression is just a lambda 
expression in disguise. "Date" is not a scoping mechanism but rather the 
type of the first formal parameter of the implicit lambda expression.

I concede that "RECEIVER" in the enum constant is confusing. The 
receiver is really the IntMapper instance. We'll rename those two constants.

Alex


More information about the type-annotations-dev mailing list