Annotation on lambda formal parameter?

Dan Smith daniel.smith at
Thu Dec 13 13:49:39 PST 2012

My understanding is:

1) Java 7 already allows annotations on method parameters (JLS 8.4.1)

2) Explicitly-typed lambdas allow the same annotations as method parameters (Lambda Spec Part B, 15.27 & 15.27.1)

3) Implicitly-typed lambdas do not allow any modifiers, including annotations (Lambda Spec again; also, the design discussions I referenced)

I thought the question was about (3), but maybe it's also about whether we _don't_ want (2)?

(FWIW, I note that exception parameters can have annotations in Java 7.  I can't seem to find the line in the spec that says what kind of ElementType they support, but some reverse engineering tells me they're PARAMETERs, not LOCAL_VARIABLEs.)


On Dec 13, 2012, at 2:32 PM, Brian Goetz <brian.goetz at> wrote:

> I think we did, but the JSR-308 EG is asking us for that opinion.
> While one might say "sure, annotations should be allowed everywhere, what's the harm", the reality is that it is not going to be easy for tools to *find* annotations on lambda formal parameters, since reflection only goes down to the method level and not the AST level.
> Also, this query is not about type annotations on the types of explicit lambda parameters; it's about annotations on the parameters themselves.  While containers use parmeter annotations for things like injection, I am having a hard time seeing a use case that is both sensible and desirable.
> On 12/13/2012 4:18 PM, Dan Smith wrote:
>> Didn't we already address this with "Modifiers on Inferred-Type Lambda Parameters", which we rejected (in email "Some rejected ideas" 5 Jul 2012, then in the August meeting)?  Or am I misunderstanding the question?
>> —Dan
>> On Dec 11, 2012, at 9:35 PM, Brian Goetz <brian.goetz at> wrote:
>>> Received from the -comments list.  Note that this is largely a query of "what does the Lambda EG think the JSR-308 EG should do".
>>> -------- Original Message --------
>>> Subject: Annotation on lambda formal parameter?
>>> Date: Tue, 11 Dec 2012 16:27:23 -0800
>>> From: Alex Buckley <alex.buckley at>
>>> Organization: Oracle Corporation
>>> To: lambda-spec-comments at
>>> CC: Michael Ernst <mernst at>
>>> Lambda EG,
>>> JSR 308 "Annotations on Java Types" will allow annotations on the
>>> manifest type of a lambda expression's formal parameter, and on the type
>>> and/or type argument in a method/constructor reference expression.
>>> Is there any interest in having 308 allow an annotation on a lambda
>>> formal parameter itself? That is, on the declaration of the parameter,
>>> rather than its type. A declaration annotation is conceptually valid
>>> even if the parameter declaration has no manifest type on which to write
>>> a type annotation.
>>> This is somewhat in scope for 308 because it already allows annotations
>>> on declarations of type parameters (filling a hole from Java SE 5.0) and
>>> it has the sub-method-level class file attributes needed to store
>>> annotations on declarations of individual lambda parameters.
>>> Alex

More information about the lambda-spec-experts mailing list