This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Soft Skills: The software developer's life manual and have John Sonmez on-line!
See this thread for details.
Win a copy of Soft Skills: The software developer's life manual this week in the Jobs Discussion forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

interface Comparable vs. equals() method

 
James Brooks
Gunslinger
Ranch Hand
Posts: 165
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, same question, but slightly different topic, so thought I'd start a new thread. Is one better than the other for any reason? My book does not offer an opinion. Thanks!
 
Nicholas Jordan
Ranch Hand
Posts: 1282
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Comparable is an interface:public int compareTo(T o);

You write that when you write some class, or you assure that it is present in some class you are going to store in an ordered collection.

the .equals method is used where == won't work, the double equals (==) simple gives the reference address of an object, it will work on primitives such as integer, double and whatever. It will not work on anything that is an instance of a class, at least on in the traditional sense, instanceof is often used where one would initially consider ==
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic