Details
-
Type:
Code Smell Detection
-
Status: Active
-
Resolution: Unresolved
-
Labels:
-
Message:Remove this type parameter and use a wildcard instead
-
Highlighting:
-
Default Severity:Minor
-
Impact:Low
-
Likelihood:Low
-
Default Quality Profiles:Sonar way
-
Targeted languages:Java
-
Remediation Function:Constant/Issue
-
Constant Cost:5min
-
Analysis Scope:Main Sources, Test Sources
Description
There is no need to declare a type parameter when naming a type constraint is not required. Using wildcards makes it easier to read.
Noncompliant Code Example
<T extends MyClass> void foo(List<T> list) { // Noncompliant, T is used only once for (MyClass myObj : list) { doSomething(myObj); } }
Compliant Solution
void foo(List<? extends MyClass> list) { for (MyClass myObj : list) { doSomething(myObj); } }