Lambdas not integrated with annotations

Jochen Theodorou blackdrag at gmx.org
Tue Aug 12 10:59:51 UTC 2014


Sorry, for the very late reply, but I did only now see this mail...

Am 30.07.2014 20:18, schrieb Remi Forax:
>
> On 07/30/2014 07:47 PM, Jochen Theodorou wrote:
>> Am 30.07.2014 16:09, schrieb Brian Goetz:
>>>> why has it not been made possible to supply lambdas as annotation
>>>> parameters? Would it have required too many changes to the language
>>>> spec? Not deemed worthwhile?
>>>
>>> One significant impediment was: Annotation parameters are restricted
>>> to the set of values that can be represented in classifies as
>>> constants: integers, strings, classes, etc.  This would have required
>>> significant changes to the JVM spec.
>>
>> MethodHandles can be constant pool elements too - afaik.
>
> yes, and a lambda inside an annotation will never capture local value
> thus can be represented as a constant method handle.
>
> But a constant lambda is not enough to reference a lambda, you need 4
> informations (the constant method handle, the functional interface, the
> single abstrat method descriptor and a reified version of this very same
> descriptor).

The later 3 are required for lambdas in Java, not MethodHandles. I was 
getting to that in the later part of my post.

> So the question is how to store a constant method handle and 2 method
> types (the method descriptors) as an annotation value
> (the functional interface is stored as the type of the annotation
> parameter).

If you could store the MethodHandle as MethodHandle, you could still 
make the needed transformation at runtime yourself.

[...]
> The real issue is that adding a new type of annotation value will
> require to update all tools that read annotations,
> all the VMs, all the bytecode transformers, all the annotation processor,
> so the question was does lambdas in annotation worth the trouble to
> update all annotation tools.
>
> the lambda EG answers 'no' to that question.

well... there are many people seeing that different ;)

> Note that instead of trying to represent a JUnit test as a lambda,
> it's better to create a new tool for doing unit testing that works like
> Ruby Rspec,
> their way to describe an unit test is in my opinion better than what we
> can do with JUnit.

Maybe, there are also things in the Groovy world like 
http://gcontracts.org/

bye Jochen


-- 
Jochen "blackdrag" Theodorou - Groovy Project Tech Lead
blog: http://blackdragsview.blogspot.com/
german groovy discussion newsgroup: de.comp.lang.misc
For Groovy programming sources visit http://groovy-lang.org



More information about the lambda-dev mailing list