java <? super Fruit>与<? extends Fruit>
2016-02-25 08:59
423 查看
package Test2016; import java.util.ArrayList; import java.util.List; public class Test2016 { public static void main(String[] args) { List<? super Fruit> first = new ArrayList<Fruit>(); //Fruit -> Apple first.add(new Apple()); first.add(new Fruit()); first.add(new RedApple()); // first.add(new Food()); //error System.out.println(first.get(0)); System.out.println(first.get(1)); List<? extends Apple> second = new ArrayList<Apple>(); second.add(null); } } class Food { } class Fruit extends Food { } class Apple extends Fruit { } class RedApple extends Apple { }
相关文章推荐
- SQL server 在OPENQUERY中使用参数
- [leetcode] 128. Longest Consecutive Sequence 解题报告
- leetcode ---Unique Paths II
- HDU 3726 Graph and Queries
- Quick Sort
- [Locked] Binary Tree Longest Consecutive Sequence
- Arduino、arm、树莓派、单片机四者有什么不同?
- C# 集合类 :(Array、 Arraylist、List、Hashtable、Dictionary、Stack、Queue)
- 浅谈 easyui tabs 的href和content属性
- QSqlQuery::value: not positioned on a valid record
- Java break continue return 的区别
- easyUI 对话框的关闭事件
- UITableView 小节-备
- GitLab: Failed to authorize your Git request: inte
- [leetcode] Divide and Conquer
- iOS UITableView的使用大全-备用
- 设计模式:Builder模式(多个构造器参数时可显著改善可读性)
- dialog子线程操作UI异常:Only the original thread that created a view hierarchy can touch its views
- dialog子线程操作UI异常:Only the original thread that created a view hierarchy can touch its views
- WeUI 入门教程