Repeatable annotations one Java <= 7
gunnar at hibernate.org
Thu Apr 24 21:58:23 UTC 2014
Thanks for the prompt response and clarification.
Based on that, I think I'll create another variant of my annotation type
and provide two artifacts, one with the variant for Java <= 7 and one for
2014-04-24 22:56 GMT+02:00 Alex Buckley <alex.buckley at oracle.com>:
> Assuming you have @Foo(...) on (say) a class declaration, javac needs to
> load the annotation type Foo to check that @Foo's element-value pairs are
> commensurate with the elements declared in Foo. Any meta-annotation on Foo
> will then have its own annotation type loaded; it is unreasonable to expect
> By marking your annotation type as repeatable, you are committing that it
> [and any annotations of that type] will only be compiled on JDK 8 and
> above, where j.l.a.Repeatable can be loaded.
> On 4/24/2014 1:46 PM, Gunnar Morling wrote:
>> I'd like to mark an annotation type as repeatable via Java 8's
>> @Repeatable meta-annotation.
>> The code accessing the annotation explicitly checks for the container
>> annotation, so it works on Java 8 (where the compiler creates an
>> instance of the container annotation) and on older versions (where the
>> container type must be used explicitly).
>> Now it's my understanding that annotation types not being present at
>> runtime don't cause issues when loading classes annotated with them. But
>> at compile time a warning is issued when compiling code using the
>> annotation on older Java versions (the compilation still succeeds):
>> "Cannot find annotation method 'value()' in type
>> 'java.lang.annotation.Repeatable': class file for
>> java.lang.annotation.Repeatable not found"
>> Is there a way for suppressing that specific compiler warning (but keep
>> others)? I think this would be helpful to allow library authors making
>> existing annotation types repeatable - thus increasing usability on Java
>> 8 - while staying compatible with older Java versions in the described
>> Or is this actually a bad pattern and one should create a new repeatable
>> variant of such an annotation type and distribute it separately (e.g.
>> using a classifier such as "jdk8" in Maven artifact terms)?
>> Many thanks,
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the compiler-dev