- Loading...
...
| Code Block | ||
|---|---|---|
| ||
var timerTimer = new (Java.type("java.util.Timer")) timerTimer.schedule(function() { print("Hello World!") }, 1000) java.lang.System.in.read() |
Here, Timer.schedule() expects a TimerTask as its argument, so Nashorn creates an instance of a TimerTask subclass and uses the passed function to implement its only abstract method, run(). In this usage though, you can't use non-default constructors; the type must be either an interface, or must have a protected or public no-arg constructor.
...