在上面的声明中,<T>
是什么?为了?
我想知道 <T>
之间的区别而没有它?它如何影响代码?
最佳答案
<T>
这里表示参数隐含类型。所以:
public static <T> List<T> createList(T... args) {
List<T> ret = new ArrayList<T>(Arrays.asList(args));
}
可以使用:
List<String> list = createList("one", "two", "three");
或
List<Integer> list2 = createList(1, 2, 3);
关于java - private static <T> T cloneX(T x) - <T> 在这里表示什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44131111/