This is an object of its own, representing the object itself. It can be understood as: a pointer to the object itself.
The usage of this in Java can be roughly divided into three types:
1. Ordinary direct reference, this is equivalent to pointing to the current object itself.
(Recommended tutorial:java introductory tutorial)
2. The names of participating members have the same name, use this to distinguish them:
public Person(String name, int age) { this.name = name; this.age = age; }
3. Quote The constructor of this class
class Person{ private String name; private int age; public Person() { } public Person(String name) { this.name = name; } public Person(String name, int age) { this(name); this.age = age; } }
For more programming-related content, please pay attention to theProgramming Introductioncolumn on the php Chinese website!
The above is the detailed content of Three uses of this keyword in java. For more information, please follow other related articles on the PHP Chinese website!