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 trial

Java Java Data Structures - Retired Organizing Data Interfaces

Tyler Combs
Tyler Combs
15,525 Points

Question for Clarity purposes regarding invocation(correct term.?)

In this video we Override the default compareTo() method. Inside this very override we also use the compareTo() method to compare mCreationDate of the BlogPosts in question. When we use this method within the override, is it just using the default method?

I'm just trying to understand how it works, as I would assume that you wouldn't be able to use compareTo() within an override of the method itself.

Thanks for clarifying!

1 Answer

andren
andren
28,558 Points

You can in fact call a method within the method's own definition, but that is not what is happening in the video you link to. You are overriding the compareTo method belonging specifically to the Treet class, however mDescription is not a Treet object and neither is mCreationDate.

mDescription is a String, and mCreationDate is a Date, and String and Date are classes of their own with their own compareTo methods defined (or inherited), and it's those methods that you are calling within the Treet class's compareTo method, not it's own compareTo.

Tyler Combs
Tyler Combs
15,525 Points

That's exactly the kind of answer I was looking for! Thank you.