返回到文章

采纳

编辑于

Java中Class.this和this的区别

java
java_shares

this指的是当前正在访问这段代码的对象,当在内部类中使用this指的就是内部类的对象,
为了访问外层类对象,就可以使用外层类名.this来访问,一般也只在这种情况下使用这种形式。

例子

class Outer{
    String data = "外部类別";

    public class Inner{
        String data = "內部类別";
        public String getOuterData(){
            return Outer.this.data;
        }
    }
}