- </blockquote></div><div><div class="blockcode"><blockquote>package generic.senior;
- import java.util.ArrayList;
- import java.util.Collection;
- /**
- * @author 面具
- *
- */
- public class SeniorTest {
- /**
- * @param args
- */
- public static void main(String[] args) {
- Collection <? extends Animal> alist = new ArrayList<Animal>();
- Animal a1 = new Cat();
- Animal a2 = new Dog();
- Cat c1 = new Cat();
- Dog d1 = new Dog();
- alist.add(a1);
- alist.add(a2);
- alist.add(c1);
- alist.add(d1);
- System.out.println(alist);
- }
- }
复制代码
为什么添加元素时报错?
|
|