Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
510 views
in Technique[技术] by (71.8m points)

java - Troubleshooting "The type parameter T is hiding the type T" warning

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Do you somewhere have a class or interface named T, or are you using T 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 that T is a type parameter)? I can reproduce your problem with this:

class T {  // A concrete type T
}

interface B<T> {  // warning: The type parameter T is hiding the type T
}

interface A<T> extends B<T> {  // warning: The type parameter T is hiding the type T
    T getObject();
}

If I remove class T, it disappears.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...