[JSR308] An implementation of Subtyping for Annotations
chaack at cs.ru.nl
Tue Sep 1 18:23:31 EDT 2009
Michael Ernst wrote:
> Thanks for the clarification. I didn't understand what you wanted to be
> done with the patch, or your view of its status. But it sounds like we are
> on the same page.
Yes. Sorry, I should have explained in my first e-mail that this patch
is just a first "draft".
> I'll assume you don't need any specific feedback unless
> you state otherwise.
We are very happy about feedback and need it.
>>> Suppose that annotation types Sub1 and Sub2 are direct subtypes of Super,
>>> whose value field has type int.
>> we disallow subtypes of
>> annotation types to "redefine" fields that have already been defined in
>> their supertypes. In your example, this means that a subtype @Sub1 of
>> @Super cannot have a "value" field, if @Super already has a "value" field.
> I think there is a misunderstanding, because my example had no redefinition
> of fields. Maybe I should have stated my example like this:
> Suppose that annotation types Sub1 and Sub2 are direct subtypes of Super,
> and Super has a value field of type int.
> (Sorry for any confusion.)
> I would expect that if Sub1 is a subtype of Super, then it is legal to
> specify the value of any of Super's fields.
Ah, now I understand. The problem is that getAnnotation(Class<T>)
returns a single annotation instead of an array, which is too
restrictive when a class has multiple annotations of type T. If we stick
with our original plan of being conservative and forbidding problematic
cases, we could forbid multiple annotations on the same element when
these annotations have a common supertype different from Object or
Annotation. I could implement such an additional syntactic check, which
is missing in the patch we posted.
Because duplicate annotations are interesting in their own right, it
might instead be better to adopt one of the two proposals from Section
D.1 of the JSR 308 specification. I personally prefer the one with the
getAnnotations()-method that returns an array of annotations. If people
are in favour of allowing duplicate annotations, I could implement one
of the proposals from Section D.1, instead of forbidding multiple
annotations with a common supertype.
More information about the JSR308