Annotating lambda expressions

Remi Forax forax at
Fri Jul 10 09:29:07 UTC 2015

On 07/10/2015 10:43 AM, Ron Pressler wrote:
> (Related to 
> It is useful to add an annotation to a lambda expression -- as in 
> foo(@Special () -> { ...}) -- which will be applied to the static 
> method implementing the lambda (not to the interface the lambda 
> implements). This would allow instrumentation tools operating on 
> method implementations to handle lambdas. So far, AFAICT, this is not 
> possible (or am I wrong?).

You're right you can not annotate a lambda expression.

> Opinions?

You can not annotate an expression in Java thus you can not annotate a 
lambda expression.

In Java, unlike say in Ruby or in Lisp, there is a clear distinction 
between the declaration part of the language and the executable part. 
Historically (Java 5), annotations was reserved to the declaration part 
of the language.
This was later expended to allow to annotate types in order to support 
"pluggable type system" in Java 8 (see the JSR 308).

As far as i know, during the initial introduction of annotations and 
during the JSR 308, the question of adding annotations on expressions 
was raised and rejected by doing a cost/benefit analysis.

> Ron


More information about the compiler-dev mailing list