What is the meaning of “this” in Java?

后端 未结 21 2561
走了就别回头了
走了就别回头了 2020-11-21 05:41

Normally, I use this in constructors only.

I understand that it is used to identify the parameter variable (by using this.something), if i

21条回答
  •  伪装坚强ぢ
    2020-11-21 06:18

    It's "a reference to the object in the current context" effectively. For example, to print out "this object" you might write:

    System.out.println(this);
    

    Note that your usage of "global variable" is somewhat off... if you're using this.variableName then by definition it's not a global variable - it's a variable specific to this particular instance.

提交回复
热议问题