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指的哪里啊?
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指的哪里啊?
楼主【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
Apple apple;
apple.getPeeled(),那么在这个函数调用中,函数里的这个this,就是指的apple这个对象!
new Person().eat(new Apple());
this就是上一句的new Apple
这是Java编程思想上的一个程序
我校网站上有视频讲解