What is the difference between Class.this and this in Java

This question shows research effort; it is useful and clear

121

This question does not show any research effort; it is unclear or not useful

Show activity on this post.

There are two ways to reference the instance of a class within that class. For example:

class Person { String name; public void setName(String name) { this.name = name; } public void setName2(String name) { Person.this.name = name; }
}

One uses this.name to reference the object field, but the other uses className.this to reference the object field. What is the difference between these two references?

首页 - Wiki
Copyright © 2011-2024 iteam. Current version is 2.125.2. UTC+08:00, 2024-05-19 07:41
浙ICP备14020137号-1 $访客地图$