泛型 通配符

来源:互联网 发布:表白的诗句 知乎 编辑:程序博客网 时间:2024/05/17 13:13
class Point<T>
{
    private T x ;
    private T y ;
    public void setX(T x){
        this.x = x ;
    }
    public void setY(T y){
        this.y = y ;
    }
    public T getX(){
        return x ;
    }
    public T getY(){
        return y ;
    }
}
public class GenericsDemo03
{
    public static void main(String args[]){
        Point<String> p = new Point<String>() ;
        p.setX("东经120度") ;
        p.setY("北纬80度") ;
        String x = p.getX() ;
        String y = p.getY() ;
        System.out.println("字符串表示,X坐标为:"+ x) ;
        System.out.println("字符串表示,Y坐标为:"+ y) ;
    }
}
原创粉丝点击