【发布时间】:2011-01-19 18:34:03
【问题描述】:
在 Java 中,是否可以在接口内使用类型变量作为数组元素?
我尝试过作为归档类型和强制转换运算符,但总是得到错误
无法对非静态类型 A 进行静态引用
interface ITest<A> {
A[] j; // Cannot make a static reference to the non-static type A
Object[] = (A[]) new Object[3]; // Cannot make a static reference to the non-static type A
}
在任何情况下,我都可以在接口内部使用构造 A[](以及枚举类型?)?
class CTest<A> {
enum MyEnum {
F, G, H;
// something that uses A[] inside. Getting the same error as above
}
}
【问题讨论】:
标签: java generics interface enums