java - 故障排除 "The type parameter T is hiding the type T"警告

标签 java generics warnings

我在 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/

相关文章:

java - JAX-RS POST 文件输入流为空

delphi - 将自定义比较器传递给 Delphi 中的通用创建过程

Java 泛型转换为通配符规则

perl - 在引用 undef 值时如何让 Perl 停止?

java - 如何在 GWT 中获取一年中的星期数

java - NetBeans 配置文件 (netbeans.conf) 位于何处?

python - Python 中 astropy.time 中的警告

ios - 这个错误是什么意思? Xcode : "Mach-O Librarian.... Log complete" Coreplot

java - MongoDB $regex 查询 "end with"特定字符

java - 创建双泛型数组 - Java