b02fcc692275001d1dddb6604daa6ad2

来自「java程序设计教程的源码」· 代码 · 共 27 行

TXT
27
字号
//【例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 + =
减小字号Ctrl + -
显示快捷键?