Inspecting the equivalent Java source for Clojure code
Inspecting the equivalent Java source for a given Clojure code provides great insight into how that might impact its performance. However, Clojure generates only Java bytecodes at runtime unless we compile a namespace out to the disk. When developing with Leiningen, only selected namespaces under the :aot
vector in the project.clj
file are output as the compiled .class
files containing bytecodes. Fortunately, an easy and quick way to know the equivalent Java source for the Clojure code is to AOT-compile namespaces and then decompile the bytecodes into equivalent Java sources, using a Java bytecode decompiler.
There are several commercial and open source Java bytecode decompilers available. One of the open source decompilers we will discuss here is JD-GUI, which you can download from its website (http://jd.benow.ca/#jd-gui). Use a version suitable for your operating system.
Creating a new project
Let's see how exactly to arrive at the equivalent...