?? holder3.java
字號:
package chapter15;
public class Holder3<T> {
private T a;
public Holder3(T a){
this.a=a;
}
public void set(T a){
this.a=a;
System.out.println("set!");
}
public T get(){
System.out.println("get!");
return a;
}
public static void main(String args[]){
Holder3<Automobile1> h1=new Holder3<Automobile1>(new Automobile1());
Automobile1 a =h1.get();
h1.set(a);
/*
* 我們看到,由于使用了泛型,類Holder3的對象就可以使用類Automobile1和Automobile2的
* 方法了。這樣,類Holder3就使用了兩種類型。
*/
Holder3<Automobile2> h2=new Holder3<Automobile2>(new Automobile2());
Automobile2 b =h2.get();
h2.set(b);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -