Even though this question is already answered , since the subject line is about ("The type parameter T is hiding the type T") , just want to add that this warning does not always mean that there is a class or actual type "T" declared somewhere in the classpath (or inner class) as all the answers/comments suggest.
Consider the following:
public class Cache<K extends Comparable<K>,V> {
private final ConcurrentHashMap<K,V> _concurrentMap = new ConcurrentHashMap<K,V>();
public <K,V> void add(K key ,V value){ // Compiler warning - The type parameter V is hiding type V (as also for K)
_concurrentMap.put(key, value); //Compiler error - K and V passed to add are now being considered different
//from whats declared for _concurrentMap variable
}
public V get(K key){
return _concurrentMap.get(key);
}
public int size(){
return _concurrentMap.size();
}
}
Because K ,V is declared at class level , the method add also "inherits" it. So you end up getting the same warning.
Below removes the warning and compiler error of course
public <E,F> void add(K key ,V value){
_concurrentMap.put(key, value);
}
And my original method is this. (Don't require additional generic types for my method)
public void add(K key ,V value){
_concurrentMap.put(key, value);
}