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. css - input元素的time控件无法选择2. python - 请教这个页面中的这两个信息能否不用无头浏览器爬取到?3. javascript - nginx反向代理静态资源403错误?4. javascript - 关于jquery的ajax post数据的问题5. 2-1Laravel中的路由加载出错6. macbook - mac下为什么不能使用mysql命令7. javascript - 前后端分离的项目可以设置cookies保持状态么?8. python - sqlalchemy中,query出来的实体,在使用的实体的属性时还是需要连接数据库么?9. objective-c - IOS 分享到微信 提示 应用消息数据错误10. javascript - 在react中写行间样式的whiteSpace不生效

网公网安备