public class TestPoint {
public static void main(String[] args) {
//泛型<>可以指定多个元素
Point<Integer,Double> p=new Point<Integer,Double>(5,51.05);
int x=p.getX();
double y=p.getY();
}
}
class Point<X,Y> {
private X x;
private Y y;
public Point(X x,Y y){
super();
this.x=x;
this.y=y;
}
public X getX() {
return x;
}
public void setX(X x) {
this.x = x;
}
public Y getY() {
return y;
}
public void setY(Y y) {
this.y = y;
}
public String toString(){
return "x="+x+","+"y= "+y;
}
}
泛型&子类
最新推荐文章于 2022-06-07 09:37:44 发布