-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Does Comparable#compareTo() have to use accessors vs fields?
PostPosted: Tue Oct 03, 2006 8:57 pm 
Newbie

Joined: Tue May 24, 2005 10:40 pm
Posts: 8
Location: Sydney, Australia
I've just been reading "Hibernate in Action"; it's an excellent book and has helped me a lot. It's definitely an essential complement to the reference docs.

Anyway, it says on p. 125 that equals() and hashCode() methods should use accessors (getters) instead of reading the "other" object's fields directly. This is all well and good (although I'm a little mystified about what's the "other" object in a hashCode() method).

My question concerns the compareTo() method in a "Comparable" domain object. Should this method (like equals() and hashCode()) use accessors instead of direct field access? I would have thought so, especially if the comparable object was being put into a sorted collection like a TreeSet. Yet there's no mention of such a requirement in either the book, the reference docs, or this forum. Is this just an oversight?

Thanks for any help,

Andrew


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.