当前位置: 代码迷 >> Java相关 >> equals的有关问题
  详细解决方案

equals的有关问题

热度:668   发布时间:2013-02-25 21:48:48.0
equals的问题
// 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;

}


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

------解决方案--------------------------------------------------------
jdk 提供的当然是效率最高的!
  相关解决方案