Java(四)集合框架4.泛型

public class Point<T>{
	private T x;
	private T y;
	public T getx()
	{
		return x;
	}
	public void setx(T x)
	{
		this.x=x;
	}
	public T getY()
	{
		return y;
	}
	public void sety(T y)
	{
		this.y=y;
	}
}

public class PointDemo {
	
	//情况1:使用String类型
	Point<String> p1=new Point<String>();
	String x1=p1.getx();
	//情况2:使用Integer类型
	Point<Integer>p2=new Point<Integer>();
	Integer x2=p2.getx();
}

猜你喜欢

转载自blog.csdn.net/qq_37282683/article/details/82913574