Before Java 8, a container annotation was required as wrapper to use multiple instances of the same annotation. As of Java 8, this is no longer
necessary. Instead, these annotations should be used directly without a wrapper, resulting in cleaner and more readable code.
This rule is automatically disabled when the project’s sonar.java.source
is lower than 8
as repeating annotations were
introduced in Java 8.
Code examples
Noncompliant code example
@SomeAnnotations({ // Noncompliant, wrapper annotations are not necessary in Java 8+
@SomeAnnotation(..a..),
@SomeAnnotation(..b..),
@SomeAnnotation(..c..),
})
public class SomeClass {
...
}
Compliant solution
@SomeAnnotation(..a..)
@SomeAnnotation(..b..)
@SomeAnnotation(..c..)
public class SomeClass {
...
}