class Person{
public void eat(Apple apple){
Apple peeled=apple.getPeeled();
System.out.println("Yummy");
}
}
class Peeler{
static Apple peel(Apple apple){
return apple;
}
}
class Apple{
Apple getPeeled(){
return Peeler.peel(this);
}
}
public class PassingThis{
public static void main(String[] args){
new Person().eat(new Apple());
}
}
这个this指的哪里啊?

解决方案 »

  1.   

    此回复为自动发出,仅用于显示而已,并无任何其他特殊作用
    楼主【Mengmengenator】截止到2008-06-22 16:30:07的历史汇总数据(不包括此帖):
    注册日期:2007-5-14
    上次登录:2008-6-22
    发帖数:0                  发帖分:0                  
    结贴数:0                  结贴分:0                  
    结贴率:100%结分率:100%
    如何结贴请参考这里:http://topic.csdn.net/u/20080501/09/ef7ba1b3-6466-49f6-9d92-36fe6d471dd1.html
      

  2.   

    这个this,比如你运行的时候:
    Apple apple;
    apple.getPeeled(),那么在这个函数调用中,函数里的这个this,就是指的apple这个对象!
      

  3.   

    对像本身.结合SUPER看一下会好点.
      

  4.   

    this就是class Apple生成的一个看不到的对象
      

  5.   

    this 指他所在类的当前操作对象
      

  6.   

    谁调用getPeeled()就是谁,你注意.前面是谁?
    new Person().eat(new Apple());
    this就是上一句的new Apple
    这是Java编程思想上的一个程序
    我校网站上有视频讲解