Added 10 more gists.
This commit is contained in:
37
PlayBall.java/PlayBall.java
Normal file
37
PlayBall.java/PlayBall.java
Normal file
@@ -0,0 +1,37 @@
|
||||
class Ball extends Throwable { }
|
||||
|
||||
class P {
|
||||
private String name;
|
||||
private P target;
|
||||
|
||||
P(String name, P target) {
|
||||
this.name = name;
|
||||
this.target = target;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setTarget(P target) {
|
||||
this.target = target;
|
||||
}
|
||||
|
||||
public void aim(Ball ball) {
|
||||
try {
|
||||
System.out.println(target.getName() + ", catch!");
|
||||
throw ball;
|
||||
} catch (Ball b) {
|
||||
target.aim(ball);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class PlayBall {
|
||||
public static void main(String args[]) {
|
||||
P parent = new P("Dad", null);
|
||||
P child = new P("Son", parent);
|
||||
parent.setTarget(child);
|
||||
parent.aim(new Ball());
|
||||
}
|
||||
}
|
||||
1
PlayBall.java/README.md
Normal file
1
PlayBall.java/README.md
Normal file
@@ -0,0 +1 @@
|
||||
[https://xkcd.com/1188/](https://xkcd.com/1188/)
|
||||
Reference in New Issue
Block a user