Java泛型类型变量作为数组类型

标签 java generics

在学习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/

相关文章:

java - Gradle Spring Boot 排除记录器错误

delphi - 如何搜索通用 TList<T> 集合?

java - 自定义 Json 序列化程序而不是 Jersey 的默认序列化程序?

java - Android - 无法使用 Android Studio Bumblebee 生成 Javadoc

java - 在java中格式化本地时间

scala - 类型参数以确保关系运算符

java - 比较 VS <?扩展比较>

java - PowerMockito 验证调用 x 次的私有(private)方法

swift - 如何通过 Result<Credentials> 类型的实例获取值?

c# - 在 Visual Studio 中的 C# 泛型类/方法上设置函数断点?