How to implement hashCode() whenever an equals() is implemented

public boolean equals(Object obj) {

// TODO Add the following, if required

// && format == docDelResponse.getFormat()

// && viewType == docDelResponse.getViewType() && type ==

// docDelResponse.getType()

// && inclCertifiedCopy == docDelResponse.isInclCertifiedCopy()

// && inclNonPatentLiterature == docDelResponse.isInclNonPatentLiterature()

// && inclNonUSReferences == docDelResponse.isInclNonUSReferences()

// && inclUSReferences == docDelResponse.isInclUSReferences()

if (obj != null && obj instanceof DocumentDeliveryResponse) {

DocumentDeliveryResponse docDelResponse = (DocumentDeliveryResponse) obj;

if (identifier != null && identifier.equals(docDelResponse.getIdentifier())) {

return true;

}

}

return false;

}

/**

* @see java.lang.Object#hashCode()

*/

public int hashCode() {

if(identifier != null) {

return identifier.hashCode();

} else {

return super.hashCode();

}

}

they are using the standard

Object.hashCode(). This means that it is highly likely that two "equal" objects

are having different hash codes.

Please let me know how i have to implement hashCode() whenever an equals() is implemented

Thanks

[1387 byte] By [Pingillia] at [2007-11-26 19:43:19]
# 1
hashCode cannot use any fields that equals does not use, and if two fields are equal, their contribution to the hashcode must be the same.Details here: http://developer.java.sun.com/developer/Books/effectivejava/Chapter3.pdf
jverda at 2007-7-9 22:26:21 > top of Java-index,Archived Forums,Java 2 Software Development Kit (J2SE SDK)...