2018-04-30
This keyword
What is this:
Represents the current object itself, or an instance of the current class, through which all methods and properties of this object can be called.
This is mainly present in two places:
1) Constructor: This represents the invocation of the currently created object
2) member method: Object A calls the method where this is located, at which point this represents the object a
When an object is created, the JVM automatically assigns a reference to the current object's this
Memory Analysis:
Use of this:
1) Use this to distinguish between variables of the same name
When a member variable has the same name as a variable in a local variable (parameter), you want to call the member variable inside the method
2) Initialize the object as a method name (the method that the constructor reloads)
This is equivalent to invoking the other constructor method of this class, which must be the first sentence of the constructor method.
3) Pass as parameter
You need to call a method in some completely detached class and pass a reference to the current object as a parameter.
Reference:
Http://www.weixueyuan.net/view/5988.html
Second, Java object-oriented (7) _ Packaging Ideas--this Keywords