invisible meerkat invisible meerkat - 1 year ago 143
Java Question

Java lambda callback in clojure

I use a java library in clojure and it has a function that accepts a callback:

How do I pass such callback in clojure? I tried anonymous function

but it doesn't work. In java using java lambdas works.

Answer Source

You can simply reify an interface.

Here is an example

(def consumer (reify java.util.function.Consumer
                (accept [this t]
                  ; here the impl 
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download