在 Java 中 <T>前一个方法签名是什么意思? [英] In Java what does <T> before a method signature mean?
本文介绍了在 Java 中 <T>前一个方法签名是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道 static <T>
在这种情况下是什么意思?或者是
?
I was wondering what static <T>
means in this context? or is it <T> void
?
我知道 static 和 void 都是什么意思,但我不确定 <T>
在这里是什么意思
I know what static and void both mean but I'm not sure what <T>
means here
static <T> void sort(List<T> list, Comparator<? super T> c)
推荐答案
意味着在此声明中使用了通用的 T
.这有两个影响;
The <T>
means that there is a generic T
being used in this declaration. This has two impacts;
- 第一个参数的第一个类型中的
T
必须与第二个参数中的类型匹配.(而? super T
意味着它必须是T
的超类或接口)如果不使用泛型,就没有办法做到这一点. - 可以使用像
Collections.
sort(list, myComparator); 这样的语句显式指定类型
- The
T
in the first type of the first argument must match the type in the second argument. (And? super T
means it must be a super class or interface ofT
) Without the use of a generic, there is no way to do this. - The type can be given explicitly with a statement like
Collections.<Integer>sort(list, myComparator);
这篇关于在 Java 中 <T>前一个方法签名是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文