java this

this 代表什么

this 应用场景

 https://docs.oracle.com/javase/tutorial/java/javaOO/thiskey.html

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

The value denoted by this in a lambda body is the same as the value denoted by this in the surrounding context.

Within an instance method or a constructor, this is a reference to the current object — the object whose method or constructor is being called.

You can refer to any member of the current object from within an instance method or a constructor by using this.

你可以在实例方法或构造器中通过使用this来指明当前对象的任意成员。

语法:

He did not refer to the report from Australia.

注意点:

this 是对象的引用

The most common reason for using the this keyword is because a field is shadowed by a method or constructor parameter.

The keyword this may be used only in the following contexts:

  •  in the body of an instance method or default method

  •  in the body of a constructor of a class 

  •  in an instance initializer of a class

  •  in the initializer of an instance variable of a class

  •  to denote a receiver parameter

原文地址:https://www.cnblogs.com/zno2/p/5611296.html