JEP 120: Repeating Annotations
Jesse Glick
jesse.glick at oracle.com
Thu Jan 5 11:49:46 PST 2012
On 11/01/2011 06:11 PM, mark.reinhold wrote:
> Posted: http://openjdk.java.net/jeps/120
This would be valuable indeed. Comments:
1. "the container annotation has a values method which returns an array of the base annotation type" is awkward since the language already defines a special implicit
method name "value" (no 's'), which is what I think should be used. Thus
@Things({@Thing(1), @Thing(2)})
could be replaced with
@Thing(1) @Thing(2)
2. Rather than forcing a separate container annotation
@ContainerAnnotation(Things.class)
@interface Thing {int value();}
@interface Things {Thing[] value();}
you could just specify that the base annotation can repeat:
@Repeatable
@interface Thing {int value();}
and introduce <T extends Annotation> List<? extends T> AnnotatedElement.getAnnotations(Class<T>) and the like. (The singleton variants would just return one of the
annotations if more than one were present.) This would seem more intuitive to me, and obviate various open design issues.
More information about the compiler-dev
mailing list