[Java] Type parameter hides another type

Description
It is possible that generic type parameters hide generic type parameters from the enclosing context. This is a source of possible confusion and bugs.

Type
Code Smell

Snippet

public class TypeParameterHidesAnotherType<T> {
	
	public class Inner0<T> { // Noncompliant
		//...
	}
	
	public class Inner1<S> { // Compliant
		//...
	}
	
	private <T> T method0() { // Noncompliant
		return null;
	}
	
	private <S> S method1() { // Compliant
		return null;
	}
	
}

Note
Also covered by Eclipse JDT.

Hello,

thank you for the rule idea. I created the specification here https://jira.sonarsource.com/browse/RSPEC-4977

Note that code samples are in the Java subtask.

1 Like