62,614
社区成员
发帖
与我相关
我的任务
分享
//比如InetAddress类为
public class InetAddress
{
private string ip;
private string port;
// getIp()方法 getPort()方法
// setIp()方法 setPort()方法
}
public boolean equals(Object other) {
if ( (this == other ) ) return true;
if ( (other == null ) ) return false;
if ( !(other instanceof InetAddress) ) return false;
InetAddress castOther = ( InetAddress ) other;
return ( (this.getIp()==castOther.getIp()) || ( this.getIp()!=null && castOther.getIp()!=null && this.getIp().equals(castOther.getIp()) ) )
&& ( (this.getPort()==castOther.getPort()) || ( this.getPort()!=null && castOther.getPort()!=null && this.getPort().equals(castOther.getPort()) ) );
}
public int hashCode() {
int result = 17;
result = 37 * result + ( getIp() == null ? 0 : this.getIp().hashCode() );
result = 37 * result + ( getPort() == null ? 0 : this.getPort().hashCode() );
return result;
}