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.
(. btn setOnAction (proxy .... ????? .... ))
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-generified EventHandler instances.
That said, Clojure doesn't even try to support them. Your Java code translates into
(.setOnAction btn
(proxy [EventHandler] []
(handle [event]
(println "Hello World"))))
See the documentation on proxy and on Java interop for more details on the syntax.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With