62,635
社区成员




public boolean equals(Object obj) {
return (this == obj);
}
/**
*一般equals的效率能更高一些,比如
*hashcode就是简单的理解就是计算对象的权值(就是一种特殊值,只有内容相等的才会一样)
*而就是是在必须进行hashcode的时候才会去调用hashcode
*
*/
//比如这是一个hashcode算法,计算比较复杂吧
hashcode(){ return ((n*(n-1)+ n - (n - 1) ) + (n - 2) ..... - 1)}
equals (Object obj){
//判断引用是否相等,如果等就直接返回,不用计算hashcode的值
if( this == obj)
{
return true;
}
else{
if(obj instanceof this.getClass().getName())
{
//这里才真正计算hashcode ,所以效率比较高
if(this.hashcode() == obj.hashcode())
{
return ture;
}
else
{
return false;
}
}
else
{
return false;
}
}
}