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

equals(other)

in the following code used in the video:

if (equals(other)) { return 0;

shouldn't it read:

if (something.equals(other)) { return 0;

??

2 Answers

Seth Kroger
Seth Kroger
56,413 Points

There's an implicit 'this.' so: if (equals(other)) { return 0;

means: if (this.equals(other)) { return 0;

Because you call compareTo() from a Treet like this: aTreet.compareTo(otherTreet) 'aTreet' is 'this' inside the method.

makes sense. thx!

Patrick Koch
Patrick Koch
40,498 Points

thx, cleaned things up!

Oziel Perez
Oziel Perez
61,321 Points

Just out of curiosity, can you literally write in "this.equals(other)" for clarification purposes? or is there another keyword? (or not?)

I was confused in this part. Thanks Seth for elaborating the code.