Calling Clojure from Java
. Intro.
Calling Clojure from Java can be tricky since most Google suggestions are outdated. This article provides clear steps to make this call, assuming you have built a JAR from a Clojure project and added it to the classpath.
. Calling Clojure.
To successfully call Clojure from Java, use these steps:
. Updated Example.
Clojure Part:
(ns com.domain.tiny (:gen-class :name com.domain.tiny :methods [#^{:static true} [binomial [int int] double]])) (defn binomial "Calculate the binomial coefficient." [n k] ...) (defn -binomial "A Java-callable wrapper around the 'binomial' function." [n k] (binomial n k))
Java Part:
import com.domain.tiny; public class Main { public static void main(String[] args) { System.out.println("(binomial 5 3): " + tiny.binomial(5, 3)); System.out.println("(binomial 10042, 111): " + tiny.binomial(10042, 111)); } }
The above is the detailed content of How Can I Successfully Call Clojure Functions from Java?. For more information, please follow other related articles on the PHP Chinese website!