rspec/rules/S4968/java/rule.adoc

40 lines
880 B
Plaintext

== Why is this an issue?
When a type variable or a wildcard declares an upper bound that is ``++final++``, the parametrization is not generic at all because it accepts one and only one type at runtime: the one that is ``++final++``. Instead of using ``++Generics++``, it's simpler to directly use the concrete ``++final++`` class.
=== Noncompliant code example
[source,java]
----
public static <T extends String> T getMyString() { // Noncompliant; String is a "final" class and so can't be extended
[...]
}
----
=== Compliant solution
[source,java]
----
public static String getMyString() { // Compliant
[...]
}
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
include::message.adoc[]
'''
== Comments And Links
(visible only on this page)
include::comments-and-links.adoc[]
endif::env-github,rspecator-view[]