(ns lol.test
(:gen-class
:name lol.test
:methods [[createHashMap [String] Java.util.HashMap]])
(:import [java.util HashMap]))
(defn -createHashMap [this s]
(HashMap. (assoc {} s "test")))
I’m trying to call clojure functions from java, for this purpose I’ve created this file which prefectly compiles with lein, I create a jar file by calling “lein uberjar”.
Now the problem is that when I call it from java like this:
lol.test l = new lol.test();
l.createhashMap("test");
it throws an ArityException
Wrong number of args (2) passed to
I’ve tried to remove ‘this’ argument from clojure code but it didn’t help. What’s the problem with this code?
You need to fix the
:methodsdeclaration. Right now you haveIt has to become
otherwise you’re only getting a 1-arity method in your compiled class.