Context
I have this piece of Java Code
btn.setOnAction(new EventHandler<ActionEvent>() {
public void handle(ActionEvent event) {
System.out.println("Hello World");
}
});
I want to convert it into Clojure.
What I know
(. btn setOnAction (proxy .... ????? .... ))
Question:
How do I handle EventHandler part in Clojure? I believe this is a Java Template. How do I create templated objects in Clojure?
In Java they’re called Generics, not Templates. Furthermore, they’re implemented using type erasure, i.e. there’s no generic information in the compiled bytecode, so that
EventHandler<Foobar>objects are compiled to be non-generifiedEventHandlerinstances.That said, Clojure doesn’t even try to support them. Your Java code translates into
See the documentation on
proxyand on Java interop for more details on the syntax.