java_类泛型基本实例

package ming;



public class Apple2<T> {



	public T info;



	public Apple2(T info) {

		this.info = info;

	}

	

	public T getInfo() {

		return info;

	}



	public void setInfo(T info) {

		this.info = info;

	}



	public static void main(String[] args) {

		//T 实际类型是String

		Apple2<String> a1 = new Apple2<String>("苹果");

		

		System.out.println(a1.getInfo());

		

		Apple2<Double> a2 = new Apple2<Double>(1.23);

		

		System.out.println(a2.getInfo());

		

	}



}


你可能感兴趣的:(java)