tomcatexpert
发贴: 52
积分: 2
|
于 2006-04-11 12:19
你不需要比较所有的Member variables,根据你写的Class具体需要就可以了.
roastduck wrote: instanceof is an operator 判断左边的object是否是右边class的instance
object instanceof class 明白了.
next point
在这个例子中,如果class value 有多个field 例如:
class Value { int i; char c; //... may be more and more }
那么在
public boolean equals(Object that) { if (this == that) return true; if ( !(that instanceof Value) ) return false; Value thatValue = (Value) that; //return (this.i == thatValue.i); //这里就要作如下修改,right? return ((this.i == thatValue.i)&&(this.c == thatValue.c)); }
是否有更简洁的写法? 毕竟field如果很多的话...最后那个return写起来会很难看的.
|