Repeatable annotations one Java <= 7
gunnar at hibernate.org
Thu Apr 24 20:46:26 UTC 2014
I'd like to mark an annotation type as repeatable via Java 8's @Repeatable
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 way.
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)?
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the compiler-dev