?? 9087da692275001d1dddb6604daa6ad2
字號:
//【例5-23】 限制泛型與通配符泛型的應用示例。
//程序清單5-23: CollectionGenFoo.java
package Generics.wildcard;
import java.util.*;
public class CollectionGenFoo<T extends Collection> {
private T x;
public static void main(String args[]) {
CollectionGenFoo<ArrayList> listFoo1 = null;
listFoo1 = new CollectionGenFoo<ArrayList>(new ArrayList());
// 由于沒有使用通配符泛型,下面兩句編譯時出錯
// CollectionGenFoo<Collection> listFoo2 = null;
// listFoo2 = new CollectionGenFoo<ArrayList>(new ArrayList());
// 以下使用了通配符泛型
CollectionGenFoo< ? extends Collection> listFoo3 = null;
listFoo3 = new CollectionGenFoo<LinkedList>(new LinkedList());
System.out.println("實例化成功!");
}
public CollectionGenFoo(T x) {this.x = x; }
public T getX() { return x;}
public void setX(T x) { this.x = x;}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -