Java uses angular brackets (<
and >
) to provide a specific type (the "type argument") to a generic type. For
instance, List
is a generic type, so a list containing strings can be declared with List<String>
.
Prior to Java 7, the type argument had to be provided explicitly for every occurrence where generics were used. This often caused redundancy, as
the type argument would have to be provided both when a field is declared and initialized.
Java 7 introduced the diamond operator (<>
) to reduce the code’s verbosity in some situations. The type argument between the
angular brackets should be omitted if the compiler can infer it.
Since the diamond operator was only introduced in Java 7, this rule is automatically disabled when the project’s sonar.java.source
is
lower than 7
.