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!
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

SPYRIDON CHRYSSIKOPOULOS
12,252 Pointswhy "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

tobiaskrause
9,160 PointsSince i have to leave i just add this here fast...sorry maybe i write more later :). Common reason for using this: http://docs.oracle.com/javase/tutorial/java/javaOO/thiskey.html
http://stackoverflow.com/questions/2429062/java-when-to-use-this-keyword
http://stackoverflow.com/questions/2411270/when-should-i-use-this-in-a-class

lambda
12,556 Pointsis 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.

SPYRIDON CHRYSSIKOPOULOS
12,252 Pointsthanks, guys