在学习Java泛型时,在Java Docs中发现了这样的说法:
A type variable can be any non-primitive type you specify: any class type, any interface type, any array type, or even another type variable.
作者:array type
他们的意思是原始数组还是ArrayList?如果它们指的是原始数组,我们应该如何编码?
最佳答案
像这样:
public class Test {
static void main(String[] asdf) {
Asdf<int[]> obj = new Asdf<int[]>();
obj.foo();
}
}
class Asdf<T> {
public void foo() { }
}
关于Java泛型类型变量作为数组类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42897135/