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

Manish Giri
Manish Giri
16,266 Points

Syntax for the compareTo() method

In the int compareTo() method, Craig uses this syntax to compare the current object with the passed-in object: if (equals(other))

I thought you refer to the object/instance which is calling your method with the 'this' keyword - so something like if(this.equals(other)) makes sense. In fact, this is what I used in the challenge and it passed.

So what's the difference between the two syntax-es? Does the first one implicitly call 'this' or is it something else I'm not aware of?

1 Answer

Kevin Faust
Kevin Faust
15,353 Points

Hey Manish,

They are both the same thing. Even if you dont write the this keyword, it's automatically implied