public interface List<E> {
void add(E);
Iterator<E> iterator();
}
List<String> ls = new ArrayList<String>(); //1 List<Object> lo = ls; //2 lo.add(new Object()); // 3 String s = ls.get(0); // 4,将object转换为string将失败。
void printCollection(Collection<Object> c) {
for (Object o: c) {
// do something
}
}
void printCollection(Collection<?> c) {
for (Object o: c) { // 1
// do something
}
} // ok
void add(Collection<? extends MyClass> c) {
c.add(new MyClass()); // wrong
} // ok
<T> add(Collection<T> c, T t) {
c.add(t);
}
List<String> l1 = new ArrayList<String>(); List<Integer> l2 = new ArrayList<Integer>(); System.out.println(l1.getClass() == l2.getClass()); // true
Object o = lsa; Object []oa = (Object[])o; List<Integer> li = new ArrayList<Integer>(); li.add(new Integer(3)); oa[1] = li; String s = lsa[1].get(0); // runtime error
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有