java - 一个泛型标签问题
问题描述
新手问一个泛型问题
public static void main(String[] args) {ArrayList<Student> al = new ArrayList<>();al.add(new Student('大石榴',17,100));al.add(new Student('地雷',20,80));al.add(new Student('张大炮',21,60));Comparator<Student> cp = new Comparator<Student>() {@Override public int compare(Student o1, Student o2) {return o1.getAge() - o2.getAge(); }}; Collections.max(al, cp);//public static <T> T max(Collection<? extends T> coll, Comparator<? super T> comp)//这是max方法的源码.// <T> 这个泛型在哪获取到的?for(Student st : al){ System.out.println(st);} }
问题解答
回答1:Java中的泛型都是使用了类型擦除,你这里的<T> 只是一个类型变量。这个方法里面也只是用来代表@param <T> the class of the objects in the collection
相关文章:
1. javascript - jQuery post()方法,里面的请求串可以转换为GBK编码么?可以的话怎样转换?2. python3.x - python 中的maketrans在utf-8文件中该怎么使用3. javascript - 一排三个框,各个框的间距是15px,距离外面的白框间距也是15px,这个css怎么写?4. javascript - nodejs调用qiniu的第三方资源抓取,返回401 bad token,为什么5. html5 - vue-cli 装好了 新建项目的好了,找不到项目是怎么回事?6. javascript - immutable配合react提升性能?7. mysql - C#连接数据库时一直这一句出问题int i = cmd.ExecuteNonQuery();8. django - python 2层文件夹导入9. python - 用urllib抓取网页上的下载链接,目标文件是xls形式,但发现抓下来的xls是空表,里面只有一句报错信息,求帮助。10. javascript - vue 手机端项目在进入主页后 在进入子页面,直接按返回出现空白情况

网公网安备