• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Comparator & Equals

 
Ronnie Phelps
Ranch Hand
Posts: 329
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I understand that as a general rule of dumb an objects comparator method should be consistent with the objects equals method. Now what if I want to sort on some common attributes that a list may have. And this attribute does not determine whether an object is equal or not. In other words is it any way possible for me to use a comparator where compare(o1,o2) == 0 and o1.equals(o2) == false?
 
John Dale
Ranch Hand
Posts: 399
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My understanding is that you can sort with Comparitor not consistant with equals, if the underlying collection is not using equals in a way inconsistant with what the search is trying to do (as is the case in the example they give involving search). But I've never tried it, nor have I fully researched it.
[ June 17, 2002: Message edited by: John Dale ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic