JEP proposed to target JDK 11: 323: Local-Variable Syntax for Lambda Parameters

Brian Goetz brian.goetz at
Tue Jan 30 15:28:18 UTC 2018

> On this thread, it has been suggested that the annotation on the lambda parameter would instead be applied to the type parameter of a generic type.  Was this an oversight, or is this expected to be part of a future design?

That sounds like someone was confused on the distinction between type annotations and declaration annotations.  When annotating a method parameter:

     m(@Foo Bar b) { }

whether @Foo annotates the declaration b or the type Bar depends on whether @Foo can be targeted at a type use or not.  Treatment of lambda parameters would be the same.  

There are no current plans to reify annotations on lambdas for reflective access at runtime.  But this doesn’t stop compile-time consumers of annotations.  You could choose to think of this as glass half full or glass half empty.

Finally, annotations is really a tertiary concern here; the main concern, as I’ve said, is regularizing the syntax (both for the various forms of lambdas itself, and between lambda parameters and local variables), and using said regularity for smoothing out future enhancements (which might include something having to do with annotations, or not.)  

More information about the jdk-dev mailing list