下文将举例this关键字应用示例
成员变量(instance)的使用
private String name;
void methodName(String name) {
this.name = name;
}
this用来表示构造函数
public TestClass(String userName) {
this(userName, true);
}
将自身实例作为参数传递
obj.methodName(this);
返回自身
void TestClass methodTest() {
return this;
}
this表示当前类的句柄
Class className = this.getClass();
版权声明
本文仅代表作者观点,不代表本站立场。
本文系作者授权发表,未经许可,不得转载。


