I am getting a warning in eclipse (the most recent version) for the following code.
public interface A<T> extends B<T> {
public T getObject();
}
The warning appears at 'T' in 'A' and reads: "The type parameter T is hiding the type T".
The weird part is that the following code generates no errors or warnings.
public interface A extends B<T> {
public T getObject();
}
But now I can't extend A while telling it what type T is.
I am completely confused. Anyone know why this is happening? Thank You.
Do you somewhere have a class or interface named
T
, or are you usingT
as a concrete type name somewhere instead of as a type parameter (which means you might have forgotten somewhere else, for example in an enclosing class, to specify thatT
is a type parameter)? I can reproduce your problem with this:If I remove class
T
, it disappears.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:
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
And my original method is this. (Don't require additional generic types for my method)
I try:
on eclipse Indigo Service Release 2 and there is no warning or error
Just to expand last answer (I know question is old and closed), I'll provide a Simplest case where you can understand the error:
Imagine an interface with a generic method such as:
If you try to override it as:
The compiler warns you:
What it means is that "Object" is a generic label here, it is not java.lang.Object. If you changed Object type to V or whatever arbitrary letter, that would not happen. But you are using and appelative which collides with an actual defined class, so compiler warns you that this Object of you is hiding what otherwise would be understood as the common Object class.