Skip to content

Instantly share code, notes, and snippets.

@codemaniac
Last active December 15, 2015 04:49
Show Gist options
  • Save codemaniac/5204067 to your computer and use it in GitHub Desktop.
Save codemaniac/5204067 to your computer and use it in GitHub Desktop.
abstract class Person {
String name;
Person(String name) {
this.name = name;
}
}
interface ICatchPlayer<T extends Throwable> {
void throww(T object);
}
abstract class CatchPlayablePerson<T extends Throwable>
extends Person implements ICatchPlayer<T> {
CatchPlayablePerson<T> target;
public CatchPlayablePerson(String name) {
super(name);
}
}
final class Ball extends Throwable {}
final class BallCatchPlayablePerson
extends CatchPlayablePerson<Ball> {
public BallCatchPlayablePerson(String name) {
super(name);
}
@Override
public void throww(Ball ball) {
try {
throw ball;
} catch (Ball b) {
target.throww(b);
}
}
}
public class CatchGame {
public static void main(String[] args) {
CatchPlayablePerson kittun = new BallCatchPlayablePerson("Kittun");
CatchPlayablePerson kuala = new BallCatchPlayablePerson("Kuala");
kittun.target = kuala;
kuala.target = kittun;
kittun.throww(new Ball());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment