📄 b02fcc692275001d1dddb6604daa6ad2
字号:
//【例5-22】 Java 5泛型的应用示例。
//程序清单5-22: GenericsFoo.java
public class GenericsFoo<T> {
private T x;
public static void main(String args[]) {
GenericsFoo<String> strFoo = new GenericsFoo<String>("Hello Generics!");
GenericsFoo<Double> douFoo = new GenericsFoo<Double>(new Double("88"));
GenericsFoo<Object> objFoo = new GenericsFoo<Object>(new Object());
System.out.println("strFoo.getX = " + strFoo.getX());
System.out.println("douFoo.getX = " + douFoo.getX());
System.out.println("objFoo.getX = " + objFoo.getX());
}
public GenericsFoo(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 + -