黑马程序员技术交流社区

标题: 看这代码哪里错了 [打印本页]

作者: 高云    时间: 2015-12-6 22:09
标题: 看这代码哪里错了
  1. class Animal {}
  2. class Dog extends Animal{}
  3. class Cat extends Animal{}
  4. class GenericDemo {
  5. public static void main(String[] args) {
  6. Collection<Object> c = new ArrayList<Object>();
  7. Collection<Animal> c1 = new ArrayList<Animal>();
  8. Collection<Animal> c2 = new ArrayList<Dog>();
  9. Collection<Animal> c3 = new ArrayList<Cat>();

  10. Collection<? extends Animal> c4 = new ArrayList<Object>();
  11. Collection<? extends Animal> c5 = new ArrayList<Animal>();
  12. Collection<? extends Animal> c6 = new ArrayList<Dog>();
  13. Collection<? extends Animal> c7 = new ArrayList<Cat>();

  14. Collection<? super Animal> c8 = new ArrayList<Object>();
  15. Collection<? super Animal> c9 = new ArrayList<Animal>();
  16. Collection<? super Animal> c10 = new ArrayList<Dog>();
  17. Collection<? super Animal> c11 = new ArrayList<Cat>();
  18. }
  19. }
复制代码

作者: LSD-ZWH    时间: 2015-12-6 22:19
我可以说我看不懂吗。。。
作者: 奔跑着    时间: 2015-12-6 22:27
c4  c10 c11非法的
作者: wyasln    时间: 2015-12-7 09:31
泛型的上下限
作者: 洪志豪1994    时间: 2015-12-7 22:27
表示不懂,等大神解读




欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2