Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- interface NewRunnable<T>
- {
- void buz(T argument);
- }
- abstract class CrazyDevice<T>
- {
- private final NewRunnable<CrazyDevice<T>> delegate;
- CrazyDevice(final NewRunnable<CrazyDevice<T>> code)
- {
- assert null != code;
- delegate = code;
- }
- void work()
- {
- delegate.buz(this);
- }
- abstract T cast();
- }
- class HellPortal extends CrazyDevice<HellPortal>
- {
- private final String name;
- HellPortal(String name)
- {
- super(new NewRunnable<CrazyDevice<HellPortal>>()
- {
- @Override
- public void buz(CrazyDevice<HellPortal> key)
- {
- key.cast().open();
- }
- });
- this.name = name;
- }
- @Override
- HellPortal cast()
- {
- return this;
- }
- void open()
- {
- System.out.println("The portal '" + name + "' is opened.");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement