concept Java code in category clojure

appears as: Java code, Java code
Clojure in Action, Second Edition

This is an excerpt from Manning's book Clojure in Action, Second Edition.

In many cases Clojure uses Java types and the standard library directly. For example, strings in Clojure are Java String objects and literal numerals are Java Long objects, and Clojure’s collections implement the same collection interfaces implemented by Java collections. Reusing Java types and interfaces has the added benefit that Java code can use Clojure types (such as its immutable data structures) seamlessly.

With the sheer amount of Java code in production (and more being written every day), no modern programming language can hope to succeed without being able to interoperate with it. Rich Hickey chose well when he picked the Java virtual machine (JVM) to host the Clojure language. Not only does Clojure benefit from the state-of-the-art technology (raw performance, HotSpot, just-in-time compilation, adaptive optimization, garbage collection, and more), but it also makes the goal of seamless Java interoperability easier to achieve. The result is that Java interop with Clojure is both elegant and easy to use. We’ll explore this facility in this chapter.

Before wrapping up this section, let’s look at a couple of macros that make life easier when dealing with Java code. We’ll first talk about memfn, which is a convenient way to convert Java instance methods into Clojure functions. We’ll then cover bean, a superconvenient way to convert a Java bean object into a Clojure map.