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


12,252 Points

why "this" isn't used? ... if (equals(other)) {...}

In ... if (equals(other)) {...}

why isn't "this" used? I would expect if (this.equals(other)) {...}

is it because we are in the class? then why should we have "this" at all? Thanks!

3 Answers

is it because we are in the class? 

Because you are inside the class "this" is implicit. You can add "this" to make it explicit and more readable. Try "this.equals(other)" and you get the same result. There are good practices for when to use/not use "this" keyword in the links in Tobias' post.

then why should we have "this" at all?

Refer to Tobias' links about we to use and not use "this" keyword. For example when inside an anonymous inside class "this" will refer to the inner class, but you want to reference the outer class. So "this" will not work in this case.