xizhenyin
发贴: 4
积分: 0
|
于 2008-09-13 12:14
问个菜鸟的问题,一个简单的程序,这里面有关 持有对方的引用是如何体现的 class Child implements Runnable { private Dad d;
Child(Dad d) { this.d = d; }
public void wakeup() { d.feed(this); //这部分this是如何调用的 ???? }
public void run() { try { Thread.sleep(4000); } catch (InterruptedException e) { e.printStackTrace(); } this.wakeup(); } }
class Dad { void feed(Child c) { System.out.println("feed............."); } }
public class Test2 {
public static void main(String[] args) { Dad d = new Dad(); Child c = new Child(d); new Thread(c).start();
}
}
-------------------------------------------------------------------- d.feed(this); //这部分this是如何调用的 ???? 持有对方的引用是怎么回事呀,这是什么设计模式
|