+ -
当前位置:首页 → 问答吧 → equals的问题

equals的问题

时间:2011-11-20

来源:互联网

// public boolean equals(Object obj)
// {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (getClass() != obj.getClass())
// return false;
// Point other = (Point) obj;
// if (x != other.x)
// return false;
// if (y != other.y)
// return false;
// return true;
// }




// public boolean equals(Object obj)
// {
// Point p = (Point)obj;
// return this.x == p.x && this.y == p.y;
// }


public boolean equals(Object o)
{
if(o == null)
{
return false;
}
if(o == this)
{
//同一个对象
return true;
}
if(o instanceof Point)
{
Point other = (Point)o;
return this.x == other.x && this.y == other.y;
}
return false;

}


帮我分析下这几个方法的效率,尽量详细点 。系统提供的那个方法是不是效率最高为什么效率最高?????????、

作者: chx10051413   发布时间: 2011-11-20

jdk 提供的当然是效率最高的!

作者: Yuerzm   发布时间: 2011-11-20

后两个根本不对。

第二个,不管3221就转型

第三个 不满足 x.equals(y)时 y.equals(x)

作者: huntor   发布时间: 2011-11-20

4984651654845131894515

作者: A792038400   发布时间: 2011-11-20

楼上的楼主能说具体点嘛??

作者: chx10051413   发布时间: 2011-11-22

热门下载

更多