Last updated 2004-06-28 by Roedy
Green ©1996-2004 Canadian Mind Products
Java definitions: 0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
You are here : home : Java Glossary : T words : this.
If you mention any instance variables in your methods without any associated pointer, e.g. height, rather than joe.height, this is automatically assumed, i.e. as if you had said this.height, meaning the height variable in the current object. Ditto for instance methods. this has many uses:
/* constructor */ public Dog ( boolean dangerous ) { this.dangerous = dangerous; } private boolean dangerous;
/** Convenience constructor to provide defaults */ public Con ( int thing ) { this( thing, false, 0 ); }
node.setParent( this );
public Dog groomDog() { washDog(); dryDog(); return this; }
Delphi and smalltalk programmers will recognize this as self.
If you don't speak assembler please ignore the following. Looking at this from the point of view of an assembler programmer, for any instance method, there is a hidden first parameter on every method call, a pointer to the object automatically generated by the Java compiler. You can refer to this parameter by the word this inside the called method.
home |
Canadian Mind Products | |||
| mindprod.com IP:[24.87.56.253] | ||||
| Your IP:[80.134.30.163] | ||||
| You are visitor number 1926. | ||||
| Please send errors, omissions and suggestions | ||||
| to improve this page to Roedy Green. | ||||
| You can get a fresh copy of this page from: | or possibly from your local J: drive mirror: | |||
| http://mindprod.com/jgloss/this.html | J:\mindprod\jgloss\this.html | |||