public class Problem<T> extends Exception { /* ...*/ } // Error can't extend Throwable catch 子句中不能使用类型变量。 可以消除对受查异常的检查 Java 异常处理的一个基本原则是, 必须为所有受查异常提供一个处理器。不过可以利用 泛型消除这个限制。关键在于以下方法: @SuppressWamings("unchecked") ...
System.out.println("添加了学生:"+ temp.id +":"+ temp.name);Studentst2=newStudent("2","李四");//添加到list中,插入到索引为0的位置,也就是第一个students.add(0, st2);Studenttemp2=students.get(0); System.out.println("添加了学生:"+ temp2.id +":"+ temp2.name);// 对象数组的形式...
为了能够放置多种类型,于是有了 <? extend T> 与 <? super T>,下面先说一些你可能原本就知道的知识: 1、对于 <? extends T> a,a 这个变量可以接受 T 及其 T 子类的集合,上界为 T,并且从 a 取出来的类型都会被强制转换为 T。重点看下面一个例子: 注意:我们先约定 Cat(猫) 继承自 Animal(动物),Re...
因为有序,ArrayList插入和删除数据时,如果不是最后一个所有修改位置的后面数据都要进行移位,因此效率低。 4、Arraylist.remove()方法里面为数字时默认为索引,若要删除内容需要将数字封装成Integer对象,当数字内容为128时,也同样可以删除,因为底层是equals,比较的是内容。 Set 1、Set的常用方法为Collection中声明的15个...
addAll(Collection<? extend E> c) boolean 将指定 collection 中的所有元素都添加到此 collection 中(可选操作) clear() void 移除此 collection 中的所有元素(可选操作) contains(Object o) boolean 如果此 collection 包含指定的元素,则返回 true containsAll(Collection<?> c) boolean 如果此 collection 包含...
addAll(Collection<? extend E> c) boolean 将指定 collection 中的所有元素都添加到此 collection 中(可选操作) clear() void 移除此 collection 中的所有元素(可选操作) contains(Object o) boolean 如果此 collection 包含指定的元素,则返回 true containsAll(Collection<?> c) boolean 如果此 collection 包含...