Method references in annotations?

Dan Smith daniel.smith at
Mon Aug 1 13:19:03 PDT 2011

This has been raised before, and the underlying problem is that there are a number of different things that look superficially similar, but that are fundamentally different:

- This request: reflection method "literals" (analogous to class literals)
- MethodHandle class file constants
- MethodHandles in general (a superset of MethodHandle class file constants)
- Method references

Each of these has been designed/proposed with a different purpose in mind, but ultimately, there's a lot of overlap.  Eventually it would be nice to have a cohesive story about all of them…


On Aug 1, 2011, at 9:18 AM, Brian Goetz wrote:

> Annotation parameters need to be constants; from the perspective of the 
> classfile, method references are not constant.  So this would not be as 
> trivial as it sounds, but not impossible if it were a priority (which it 
> is not currently.)
> On 8/1/2011 11:30 AM, Paul Benedict wrote:
>> Project Lambda is introducing method references. That's a feature I
>> desire because one of my gripes with JPA (or any annotations that
>> relate to properties) is the necessity to spell-out the property
>> names.
>> Example:
>> @OneToMany(cascade=ALL, mappedBy="customer")
>> Would something like this now be possible (provided the annotation was
>> refactored)?
>> @OneToMany(cascade=ALL, mappedBy=#SomeClass.getCustomer)
>> Paul

More information about the lambda-dev mailing list