日期:2014-05-20  浏览次数:20677 次

为什么要用this,说详细点
package srcs;
interface Lol{
void show();
}
public class 内部类2 {

public static void main(String[] args){

Lol l=new Lol(){
public void show(){
System.out.println("A");
this.test();
}
public void test(){
System.out.println("B");
}
};
l.show();

Object o=new Object(){
public String toString(){
this.show();
return "C";

}
public void show(){
System.out.println("GG");
}
};
System.out.println(o);
}
}

------解决方案--------------------
this指示你上面new的对象啊,也叫当前对象
------解决方案--------------------
引用:
太模糊了,tmd到底当前的对象是哪个啊,哪个类的


。。。不要激动
当前对象就是指,你在程序中new出来的对象,比如: Object obj = new Object(); 则this就是指向obj,this就是这个obj。画图不易啊!!!如图: