Sometimes you want to glue solutions writen in different JVM languages. To do so you need to call that languages or somehow use java bitecodes. What is purest, safest, nicest way to do so in Clojure?
For example what is best way to call Scala from Clojure?
(I know that other way is easy. You can generate .class by gen-class as it writen in Can you mix the JVM languages? ie: Groovy & Clojure, but that just allow you to use clojure from other languages.)
Since Clojure runs on the JVM, you can access any known class which is on your classpath out of Clojure. Here is a Scala example. To make the classpath setup and dependency management easier, use Leiningen to generate a project.
In the project folder, modify the project.clj and add a dependency for Scala’s language libraries, and the scala-src folder to the classpath:
Create the directory scala-src, and in that folder create the following Scala class:
Compile the class using scalac. Now run lein deps to download the dependencies. Launch the Clojure REPL by running lein repl. You can import the Scala class, instantiate it and call the sayHelloToClojure method.
This is just compatible to the way you could use Scala classes and code out of Java. That can get tricky, a quote from the Frequently Asked Questions – Java Interoperability: