'this' in Java: How does it work?

前端 未结 7 457
孤街浪徒
孤街浪徒 2020-12-11 16:50

I know that \'this\' is acting as reference in Java. We can use it inside the class members only.

What I am asking is... because it is used in the members of the cl

7条回答
  •  执念已碎
    2020-12-11 17:22

    How exactly was [this] defined in Java?

    In Java this is defined by the Java Language Specification as a keyword and therefore is not an ordinary variable name and has special behaviour.

    The behaviour of this is defined in section 15.8.3 of the specification. For example:

    When used as a primary expression, the keyword this denotes a value, that is a reference to the object for which the instance method was invoked (§15.12), or to the object being constructed.

提交回复
热议问题