Hi

The "New Documentation!" news item
http://appfuse.org/display/APF/2008/05/13/New+Documentation%21
recommended the article "AppFuse: Igniting your applications with AppFuse":
http://www.ociweb.com/jnb/jnbMay2008.html

That article has a useful reference to the relevant chapter of "Effective
Java" regarding implementation of equals() and hashCode() methods - I hadn't
realised that text was available online.
http://java.sun.com/developer/Books/effectivejava/Chapter3.pdf

However, the article then fails to follow the book's advice, with code like
this in the hashCode() implementation:

result = (description != null ? description.hashCode() : 0);
result = result * (int)hours;
result = result * (project != null ? project.hashCode() : 0);

Notice that any 0 or null encountered will give a result of 0.

Following Joshua Bloch's advice in the book, this should be rewritten
(taking into account the fact that the hours field is a double):

result = (description != null ? description.hashCode() : 0);
long hoursBits = Double.doubleToLongBits(hours)
result = 37 * result + (int)(hoursBits ^ (hoursBits >>> 32));
result = 37 * result + (project != null ? project.hashCode() : 0);

regards

  Justin Forder
-- 
View this message in context: 
http://www.nabble.com/Bad-hashCode-implementation-in-OCIWeb-%22-Igniting-your-applications-with-AppFuse%22-article-tp19011861s2369p19011861.html
Sent from the AppFuse - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to