Learn why Clojure macros and Java reflection solve different metaprogramming problems: macros rewrite forms before runtime, while reflection inspects JVM types at runtime.
Macros and Java reflection can both feel dynamic to a Java engineer, but they happen at different times and solve different problems.
| Mechanism | How to think about it |
|---|---|
| Clojure macro | Happens before evaluation or compilation of the expanded form. Ask: “Can better syntax generate ordinary code here?” |
| Java reflection | Happens at runtime. Ask: “Do I need to inspect or call a type I do not know until runtime?” |
| Clojure interop reflection | Runtime fallback emitted by the Clojure compiler when target types are unclear. Ask: “Should I add type hints or simplify the call site?” |
Use this section to separate those concerns. A macro is not a faster reflection API, and reflection warnings in Clojure are usually not solved by writing a macro. They are solved by making the JVM target type visible.