A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 高云 中级黑马   /  2015-12-6 22:09  /  770 人查看  /  4 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

  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. }
复制代码

4 个回复

倒序浏览
我可以说我看不懂吗。。。
回复 使用道具 举报
c4  c10 c11非法的
回复 使用道具 举报
泛型的上下限
回复 使用道具 举报
表示不懂,等大神解读
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马