Browse Learn Clojure Foundations as a Java Developer

Generated Java Classes from Clojure

Use gen-class, method overrides, and ahead-of-time compilation only when Clojure code must present named Java classes to Java callers, launchers, or framework scanners.

Most Clojure code should stay namespace- and data-oriented, but some Java integration points require a named class. Framework launchers, reflection-based scanners, servlet containers, build tools, and legacy Java modules may need to instantiate or discover a class by name rather than receive a Clojure function or inline adapter.

This section covers the heavier interop path:

  • defining Java-visible classes with gen-class
  • implementing or overriding Java methods from Clojure functions
  • compiling and packaging generated classes for Java callers

Use these pages when an inline reify or proxy object is not enough.

In this section

  • Defining Java Classes with gen-class
    Define Java-visible classes from Clojure with gen-class when Java code must instantiate the type, call named methods, or rely on ordinary JVM class discovery.
  • Overriding Java Methods from Clojure
    Override Java methods from Clojure with proxy, reify, or generated classes while keeping the adapter small and the business logic in ordinary functions.
  • Compiling and Using Generated Classes
    Compile gen-class namespaces into JVM bytecode, package the result, and make the generated classes usable from Java applications without turning the whole Clojure codebase into class-first design.
Revised on Saturday, May 23, 2026