public boolean equals(Object otherObject)
{
if (this==otherObject)return true;
if (otherObject==null)return false;
if (getClass()1=otherObject.getClass())return false;
Item other=(Item) otherObject;
return description.equals(other.description)&&parNumber==other.partNumber;
}
请问这段代码有什么作用
{
if (this==otherObject)return true;
if (otherObject==null)return false;
if (getClass()1=otherObject.getClass())return false;
Item other=(Item) otherObject;
return description.equals(other.description)&&parNumber==other.partNumber;
}
请问这段代码有什么作用
不过好像有个地方不对getClass()1=otherObject.getClass()中间那个应该是!,怎么是个1呢
这个方法就是判断两个对象是否相等,如果不重写的话调用Object的equal方法,那个是比较内存地址是否相等来判定两个对象是否相等的