Home >Java >JavaBase >Is java this a pointer?

Is java this a pointer?

angryTom
angryTomOriginal
2019-11-18 10:03:312893browse

Is java this a pointer?

java Is this a pointer?

There is no concept of pointers in java, but there are similar pointers in c The concept of handle is slightly different in syntax, but the nature is the same. They both refer to an object of a certain class.

this in java

When local (or formal parameter) variables and member variables have the same name, Use this to represent member variables in methods to distinguish them.

If you call another method of the same class inside the method, you do not need to use this. Similarly, if there are no local variables and member variables with the same name in a method, then there is no need to use this when using member variables in this method. This has the following meaning:

1. Indicates a reference to the current object!

2. Indicates using class member variables instead of function parameters.

3. Used to reference the constructor that satisfies the specified parameter type in the constructor (actually, it is also the constructor). But you must be very careful here: only one constructor can be referenced and it must be at the beginning!

4. Obviously this cannot be used in static methods, because this refers to the current object, and static has no object.

php Chinese website, a large number of free Java introductory tutorials, welcome to learn online!

The above is the detailed content of Is java this a pointer?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:When does java trigger gcNext article:When does java trigger gc