私人静态< T> T cloneX(T x) - 什么< T>在这里表示? [英] private static <T> T cloneX(T x) - What does the <T> signify here?
本文介绍了私人静态< T> T cloneX(T x) - 什么< T>在这里表示?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在上面的声明中,< T>
是什么?
In the above declaration, what is the <T>
for?
我想知道< T>
之间的区别,而没有它?它是如何影响代码的?
I would like to know the difference between having <T>
and not having it? How does it affect the code?
推荐答案
< T>
表明类型是从参数中隐含的。所以:
<T>
here indicates the type is implied from the arguments. So:
public static <T> List<T> createList(T... args) {
List<T> ret = new ArrayList<T>(Arrays.asList(args));
}
可以使用:
can be used:
List<String> list = createList("one", "two", "three");
或
List<Integer> list2 = createList(1, 2, 3);
这篇关于私人静态< T> T cloneX(T x) - 什么< T>在这里表示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文