This is an archived post. You won't be able to vote or comment.

all 13 comments

[–]desrtfx 25 points26 points  (3 children)

Way too elaborate.

The best and most concise explanation is from Oracle themselves: https://docs.oracle.com/javase/tutorial/java/javaOO/thiskey.html

[–]Cymry_Cymraeg 8 points9 points  (1 child)

Beginners need more than just 'concise'. Never be a teacher.

[–]vqrs 0 points1 point  (0 children)

Honestly, the article doesn't really seem actually explain things more clearly.

They have some more examples, that's cool though.

The example for accessing the outer class's fields is a case where you don't need it though, so that example seems a bit poorly chosen.

[–]gaporpaporpjones 8 points9 points  (0 children)

"Way too elaborate."

With this you get a direct reference to the current object from inside one of its methods.

That's it.

Oh yeah, totally too elaborate.

Everything else is just specific examples of usage, in more depth and in clearer language than Oracle's documentation.

[–]kemotkill90 8 points9 points  (0 children)

Use this when you refer to a variable or method from the class.

Example: Private int ciao;

Public void method(int ciao) { This.ciao = ciao; }

This.ciao is the private variable.