Skip to content

Instantly share code, notes, and snippets.

@wololock
Created November 15, 2018 10:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wololock/eba15330c871ee1614c792165c7b35fd to your computer and use it in GitHub Desktop.
Save wololock/eba15330c871ee1614c792165c7b35fd to your computer and use it in GitHub Desktop.
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