私有静态& lt; T& gt;T cloneX(T x)-< T& gt;在这里表示? [英] private static <T> T cloneX(T x) - What does the <T> signify here?

查看:63
本文介绍了私有静态& lt; T& gt;T cloneX(T x)-< T& gt;在这里表示?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在上面的声明中,< 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));
}

可以使用:

List<String> list = createList("one", "two", "three");

List<Integer> list2 = createList(1, 2, 3);

这篇关于私有静态&amp; lt; T&amp; gt;T cloneX(T x)-&lt; T&amp; gt;在这里表示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆