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. android - NavigationView 的侧滑菜单中如何保存新增项(通过程序添加)2. javascript - 微信公众号网页使用redux如何管理用户刷新?3. 提示语法错误语法错误: unexpected ’abstract’ (T_ABSTRACT)4. tp5 不同控制器中的变量调用问题5. 这段代码既不提示错误也看不到结果,请老师明示错在哪里,谢谢!6. php - 第三方支付平台在很短时间内多次异步通知,订单多次确认收款7. php7.3.4中怎么开启pdo驱动8. ueditor上传服务器提示后端配置项没有正常加载,求助!!!!!9. mysql服务无法启动1067错误,谁知道正确的解决方法?10. 老师 我是一个没有学过php语言的准毕业生 我希望您能帮我一下
