Clojure Proxy Java Templates

clojure

Solution

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.

Problem

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?

Original source

Related problems