@Target annotation with empty set
Joe Darcy
joe.darcy at oracle.com
Mon Mar 11 21:06:41 PDT 2013
On 3/11/2013 3:54 PM, Steve Sides wrote:
> On 3/11/2013 2:16 PM, Alex Buckley wrote:
>> On 3/11/2013 1:43 PM, Jonathan Gibbons wrote:
>>> Is it ever reasonable to have a @Target annotation with an empty set?
There is one case where this does what you want: when you want to
declare an annotation type that can only be used as the return value for
a method in another annotation type.
>>>
>>> -- Jon
>>>
>>>
>>> import java.lang.annotation.*;
>>>
>>> @Target({})
>>> @interface TC { T[] value(); }
>>>
>>> @Repeatable(TC.class)
>>> @interface T { }
>>>
>>> @T @T
>>> class C { }
>>
>> Reasonable? No. Legal? Yes.
>>
>> I allude to something like this case in a note in the rep.annos spec:
>>
>> "If Foo has no @Target meta-annotation but FooContainer has an
>> @Target meta-annotation, then @Foo may only be repeated on program
>> elements where @FooContainer may appear."
> So, is no @Target the same as and empty @Target?
No; that case is covered in the existing specification.
-Joe
More information about the enhanced-metadata-spec-discuss
mailing list