📄 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 + -