This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Overriding CompareTo in java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Overriding CompareTo in java" Watch "Overriding CompareTo in java" New topic
Author

Overriding CompareTo in java

Suresh KumarPandey
Ranch Hand

Joined: Sep 08, 2012
Posts: 46
[Added code tags. See UseCodeTags for details]


The above compareTo method giving error that it should return integer ,can anyone tell please tell why.
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4342
    
    7

What does your compareTo method return if name.compareTo(c.name) is not zero?
Suresh KumarPandey
Ranch Hand

Joined: Sep 08, 2012
Posts: 46
Thanks Matthew ,i got it we need to return something if the IF condition is not satisfied
Thakur Sachin Singh
Ranch Hand

Joined: Jun 15, 2010
Posts: 232

So where you put return statement if the IF condition is not satisfied and what value you will return?


SCJP 6- 91%, IBM DB2, IBM RAD Certified
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18509
    
  40

Thakur Sachin Singh wrote:So where you put return statement if the IF condition is not satisfied and what value you will return?


What is returned is specific to the OP class -- I am not sure if the OP mentioned it in detail in this topic. And how it is done would depend on how complex it is -- and again, specific to the OP class. The Java compiler simply ensures that all code paths through the method returns a value.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Overriding CompareTo in java
 
Similar Threads
Can someone tell me why?
Plz xplain this code on TreeSet
Can someone shed some light on this program
Casting
protected and default constructor