我在 Eclipse(最新版本)中收到以下代码的警告。
public interface A<T> extends B<T> {
public T getObject();
}
警告出现在“A”中的“T”处,内容为:“类型参数 T 正在隐藏类型 T”。
奇怪的是下面的代码没有产生错误或警告。
public interface A extends B<T> {
public T getObject();
}
但是现在我不能在告诉它 T
是什么类型时扩展 A。
我完全糊涂了。有人知道为什么会这样吗?
最佳答案
您是否在某处有一个名为 T
的类或接口(interface),或者您是否在某处使用 T
作为具体类型名称而不是类型参数(这意味着您可能忘记在其他地方(例如在封闭类中)指定 T
是类型参数)?我可以用这个重现你的问题:
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();
}
如果我删除类 T
,它就会消失。
关于java - 故障排除 "The type parameter T is hiding the type T"警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10011758/