interface A<T> {
interface B {
// Results in non-static type variable T cannot
// be referenced from a static context
T foo();
}
}
这附近有没有?为什么从 A.B 引用时 T 被视为静态?
最佳答案
默认情况下,接口(interface)的所有成员字段都是public
、static
和final
。
由于默认情况下内部接口(interface)是static
,您不能从静态字段或方法中引用T
。
因为 T
实际上与类的实例相关联,如果它与静态字段或与类相关联的方法相关联,那么它就没有任何意义
关于Java 泛型 : non-static type variable T cannot be referenced from a static context,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10963601/