Java logoJava/
JAVA-W1018

Type bound extends final typeJAVA-W1018

Minor severityMinor
Anti-pattern categoryAnti-pattern

This type parameter appears to extend a final class, which is a useless operation. Just specify the class directly.

The only class which inherits from a final class is that class itself. Thus, just using the type directly is enough, there is no need to specify it as a type bound.

Bad Practice

The method below accepts an argument with a generic type T that extends java.lang.String. However, String is a final class and cannot be extended further. This means that the only class that can be accepted by this method is String itself.

<T extends String> void thing(T a) {
    System.out.println("a" + a);
}

Use the class directly.

void thing(String a) {
    System.out.println("a" + a);
}

References

Oracle Java 11 Language Specification - Section 4.5.1 - Type Arguments of Parameterized Types Oracle Java 11 Language Specification - Section 8.1.1.2 - Final Classes