File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes compareTo Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "compareTo" Watch "compareTo" New topic


adam Lui
Ranch Hand

Joined: Sep 03, 2007
Posts: 186
source: K & B page 553

I understand what line 1 does (compareTo), but doesnt it recursively invoke compareTo itself (possible for any method?) or it is invoking some other compareTo in extending classes?
Kelvin Chenhao Lim
Ranch Hand

Joined: Oct 20, 2007
Posts: 513
Not sure what you mean. That statement is calling the compareTo method of String, since title is a String reference. All classes that implement the Comparable interface have a compareTo method.

To answer your secondary question, yes, recursive method calls are fine in Java. This includes infinite recursive loops, which the compiler will accept but will cause the JVM to eventually throw a StackOverflowError.

SCJP 5.0
Burkhard Hassel
Ranch Hand

Joined: Aug 25, 2006
Posts: 1274
Howdy ranchers,

the invokation indicated is not recursive. It calls a method of a differnt class. To be truely recursive it has to call itself.
You can for example calculate the faculty n! of a number by using a recursive method.


all events occur in real time
I agree. Here's the link:
subject: compareTo
It's not a secret anymore!