<>中代码
class Generic<T>{}
class ArrayofGenericReference{
static Generic<Integer>[] gia;
}
上面代码编译不通过,但是去掉static改成Generic[] gia = new Generic[1];
后编译运行都没有问题。虽然书上说不能创建泛型数组,但是Generic[] gia = new Generic[1];却可以正常编译运行。请问为什么?
<>中代码
class Generic<T>{}
class ArrayofGenericReference{
static Generic<Integer>[] gia;
}
上面代码编译不通过,但是去掉static改成Generic[] gia = new Generic[1];
后编译运行都没有问题。虽然书上说不能创建泛型数组,但是Generic[] gia = new Generic[1];却可以正常编译运行。请问为什么?
我给你说一下,数组本来就定义了,要存放的类型了,比如 int[] abc 就说明里面放的就是int类型的,所以你这么写肯定不对了,把数组跟集合的区别看一下
就明白了。