Browse Clojure Foundations for Java Developers

Creating Java Objects

Construct Java objects and configure them cleanly (often with doto) at interop boundaries.

Sometimes you need a Java object: a client, a builder, a stream, a time type, a JDBC datasource. In idiomatic Clojure, you create and configure Java objects at the edges, then keep the core of your program working with plain data.

Two patterns show up a lot:

  • Constructor calls like (java.util.ArrayList. 10) or (java.io.File. "x.txt")
  • doto for “configure this object and return it”

The aim is to keep object creation localized so it does not leak across your codebase as an implicit global dependency.

In this section

Revised on Friday, April 24, 2026