What does this in java mean?
Nov 13, 2019 am 11:26 AMthis represents the current object. this calls the attributes in this class, that is, the member variables in the class; this calls other methods in this class;
this To call other constructors in this class, the call must be placed in the first line of the constructor. (Recommended study: java course)
This this must be used in a method of a certain class.
For example:
public class persion{ private String name=null; private int age; public void setName(String name){ this.name=name; } public String getName(){ return name; } }
In this class, the first variable in the setName method uses this to distinguish it from the parameter this of this method. Indicates that this name refers to the name attribute of the Person class, not the name parameter. If this is removed, after executing this method, the name attribute of the Person class will still be null
returned by the getName method The name of the Person class is not used because it is not necessary, because the compiler will know that this name refers to the name of the Person and not other names (because there is no name variable to find a way to confuse it). Of course, you can also explicitly use return this.name in this method, that’s right.
The above is the detailed content of What does this in java mean?. For more information, please follow other related articles on the PHP Chinese website!

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Break or return from Java 8 stream forEach?
