`reify` creates a one-off object that implements one or more interfaces, with method bodies written inline. Use it when a Java API needs a listener or another short-lived interface implementation, and maintaining a named class would add little value. It can implement interfaces, but it cannot extend a Java class. section 15.6 section 15.0
Register a property-change listener
Suppose `ClassWithProperty` fires an event when its value changes. The reified object supplies the required `PropertyChangeListener` method: ```clojure (import 'java.beans.PropertyChangeListener) (import 'ClassWithProperty) (let [observed (ClassWithProperty.) listener (reify PropertyChangeListener (propertyChange [this evt] (let [{:keys [oldValue newValue]} (bean evt)] (println "Button Clicked!" oldValue newValue))))] (.addPropertyChangeListener observed listener) (.setValue observed "I click")) ;; Button Clicked! nil I click ``` The listener is created where it is registered; no separate listener class is needed. section 15.6
Supply a protocol implementation
A protocol has an interface that `reify` can implement. Here, a wrapper supplies `IKVReduce` so `reduce-kv` can process entries from a Java `HashMap`: ```clojure (import 'java.util.HashMap) (import 'clojure.core.protocols.IKVReduce) (def m (doto (HashMap.) (.put :a "a") (.put :b "b") (.put :c "c"))) (reduce-kv (fn [acc k v] (assoc acc (str k) v)) {} (reify IKVReduce (kv-reduce [this f init] (reduce-kv f init (into {} m))))) ;; {":b" "b", ":c" "c", ":a" "a"} ``` Calling `reduce-kv` on `m` directly instead raises a missing-implementation exception. section 15.6
Choose `proxy` when a Java framework requires class extension or another proxy feature. For quick interface-only instances, `reify` is generally faster, though proxy class caching can help with interfaces that have many methods. Reducers and folders also use `reify` to give collections reduction or folding behavior. section 15.5 section 15.6 section 7.1.2
