Data Type Conversion Between Java and Clojure
Convert collections, null/nil, numbers, arrays, and common Java types at the boundary.
Interop usually fails (or becomes ugly) at the type boundary: null vs nil, Java arrays vs Clojure sequences, mutable collections vs persistent data.
A practical rule for Java engineers:
Convert once, at the edge. Keep the inside of your program on one side of the boundary.
Common conversions you will see:
- Java collections ↔ Clojure maps/vectors (
into, seq, vec)
- arrays ↔ seqs (
into-array)
null ↔ nil (be explicit and defensive)
This section helps you build consistent conventions so interop code stays predictable and reviewable.
In this section
-
Primitive Types and Wrappers: Understanding Clojure and Java Interoperability
Explore how Clojure handles Java primitive types and their wrapper classes, including automatic boxing and unboxing, and ensuring correct type usage.
-
Java Collections Interoperability in Clojure: Conversion Techniques and Best Practices
Explore seamless conversion between Java collections and Clojure collections, enhancing interoperability and leveraging the strengths of both languages.
-
Handling Arrays in Clojure: Java Interoperability and Beyond
Explore how to handle Java arrays in Clojure, including creation, access, and modification. Learn about functions like make-array, to-array, and aget, and understand the nuances of Java-Clojure interoperability.
-
Handling `null` Values in Clojure: A Guide for Java Developers
Explore how Clojure represents Java's `null` as `nil`, and learn strategies for handling `nil` safely in your Clojure applications.