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 - js中数组的undefined为什么不会被遍历2. 求救一下,用新版的phpstudy,数据库过段时间会消失是什么情况?3. javascript - 如何将一个长为365的数组对象按月份切割成12组?4. css3不包括5. java - 如何分割形如(operator arg1 arg2 ... argn)的字符串?6. thinkphp中Controller里面使用Request::File(’image’);7. java - 做一个视频播放器,想实现一个功能,如果3秒不点击屏幕任何,则下方一个界面布局(显示按钮那些的)自动消失。8. 编辑管理员信息时,为什么没有修改过的内容会为空?9. mysql - 看这条sql有可能被注入吗10. java 如何列出jar包中jar包里的所有文件和目录?

网公网安备