7.7. The this Reference

The this keyword allows you to specify the current object, whatever it might be. This obviates the need to store a separate copy of every variable and method for each instantiation of a class. The this reference always refers to the current object. Let's say it another way. When writing this.name, this refers to the current object's copy of name.

When you invoke a new object method from the same object, there is no need to prefix a this reference. The this reference is included implicitly by Java:

public class Test {

void someMethod() {
     anotherMethod();
     }

void anotherMethod() {
     // method definition here...
     }
}

In the above code, anotherMethod is invoked without an object reference. This code would compile because when ...

Get Java™ for ColdFusion® Developers now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.