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是如何调用的 ????
持有对方的引用是怎么回事呀,这是什么设计模式
|
|