Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialHImanshu Shukla
703 Pointsimplementing an interface and overriding its method
i have this doubt that when we implemented the Comparable interface and override the method int compareTo().
in the overridden method we typecasted the object to type Treet but later in a condition where if the dates are equal we go on and compare the mDescription Strings we simply called the compareTo() method..
My doubt is during the second call, had recursion occured or the simple String.compareTo() method responded to call.
well from the execution of code it is understandable that for sure the second thing had happened cause if recursion had occurred then an error would have generated sating String can't be converted to type Treet..
My doubt is how did the compiler know which compareTo() to call???
1 Answer
Juraj Sallai
7,188 PointsIt is because you are calling date.compareTo(other.date); and variable date is type Date. So it uses Date.compareTo() method, not the compareTo() method we just created. You can check my comment here