There are situations when you are interacting with Java libraries, where you must send an instance of a specific Java class to some method; writing a class isn't the best option, you should rather create an instance that conforms to a contract expected by some framework on the fly. We have two options to do this:
Proxy: It allows you to implement a Java interface or extend from some super class. In reality, it creates a new object that calls your Clojure functions when needed
Reify: Reify allows you to implement interfaces and Clojure protocols (we will see them later). It is not capable of extending classes. It is a better performant than the proxy and should be used whenever possible.
Let's look at a minimal example:
(import '(javax.swing JFrame JLabel JTextField JButton) '(java.awt.event ActionListener) '(java.awt GridLayout)) (defn sample [] (let [frame (JFrame. "Simple Java Integration") sample-button (JButton. "Hello")] (.addActionListener...