码迷,mamicode.com
首页 > 其他好文 > 详细

使用泛型来优化坐标类

时间:2017-06-05 15:47:35      阅读:138      评论:0      收藏:0      [点我收藏+]

标签:new   poi   code   set   ack   out   system   []   oid   

package fanxing.cn;
/*
 * 使用泛型来优化 坐标类的demo
 */
//申明泛型类
class Point <t> {
private t x;
private t y;
public void setx(t  x){
    this.x = x;
}
public t getx(){
    return x;
}
public void sety(t  y){
    this.y = y;
}
public t gety(){
    return y;
}
}
public class FanXingDemo {
    public static void main(String[] args) {
        //泛型对象定义
        //问题:这里为啥不用int ,要用Integer 呢,因为泛型中只能使用包装类
        Point <Integer>p = new Point<Integer>();
        p.sety(89);
        p.setx(34);
        System.out.println(p.getx());
        System.out.println(p.gety());
    }

}

 

使用泛型来优化坐标类

标签:new   poi   code   set   ack   out   system   []   oid   

原文地址:http://www.cnblogs.com/yuanyuan2017/p/6944864.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!