Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- final class WaitTest2 {
- public static void main(String[] args) {
- new WaitTest2().run();
- }
- void run() {
- class Closure {
- private final Runnable runnable;
- public Closure(Runnable runnable) {
- this.runnable = runnable;
- }
- void call() {
- runnable.run();
- }
- }
- Closure closure = new Closure(() -> {
- try {
- wait(1000);
- System.out.println("AHA!");
- } catch (InterruptedException e) {
- throw new RuntimeException(e);
- }
- });
- synchronized (this) {
- closure.call();
- }
- }
- }
Add Comment
Please, Sign In to add comment