clojure-java-interop

How to handle java variable length arguments in clojure?

前提是你 提交于 2019-11-26 15:26:44
I'am wrapping a java lib into clojure, but i have problems dealing with variable length arguments. Say, TestClass.aStaticFunction(Integer... intList){/*....*/} How could i call this function in clojure? Since Java varargs are actually arrays , you can call vararg functions in Clojure by passing an array. You could convert a Clojure seq (maybe by using Clojure's variety of variable argument functions) into an array: (TestClass/aStaticFunction (into-array Integer [(int 1),(int 2)])) or (defn a-static-function-wrapper [& args] (TestClass/aStaticFunction (into-array Integer args)) Or make an array

Calling clojure from java

南笙酒味 提交于 2019-11-26 00:17:22
问题 Most of the top google hits for \"calling clojure from java\" are outdated and recommend using clojure.lang.RT to compile the source code. Could you help with a clear explanation of how to call Clojure from Java assuming you have already built a jar from the Clojure project and included it in the classpath? 回答1: Update : Since this answer was posted, some of the tools available have changed. After the original answer, there is an update including information on how to build the example with