Created
November 15, 2018 10:50
-
-
Save wololock/eba15330c871ee1614c792165c7b35fd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment