December 1999
Intermediate to advanced
816 pages
20h 27m
English
This ambiguity in the code, which might result in unexpected results, is avoided by using the this object reference. The object reference that points to the current object whose code you are executing at the moment is this. You don't declare this yourself. It's supplied by the Java runtime system. So if I'm in the verify method, and I want to ask the current object to do something, I could code
this.someMethod();
Except for special uses we will see later, it is generally redundant to code this. In the preceding example, however, we need to use this. Listing 5.2 shows the class with a modification that removes the ambiguity and behaves as desired.
public ... |
Read now
Unlock full access