Take the 2-minute tour ×
(ns lol.test
   :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();

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?

share|improve this question
What is your return type? should it be java.util.HashMap? –  Abimaran Kugathasan Jun 20 '12 at 12:24

2 Answers 2

up vote 2 down vote accepted

You need to fix the :methods declaration. Right now you have

:methods [[createHashMap [String] java.util.HashMap]]

It has to become

:methods [[createHashMap [Test String] java.util.HashMap]]

otherwise you're only getting a 1-arity method in your compiled class.

share|improve this answer
Java.util.HashMap or java.util.HashMap ..? –  Abimaran Kugathasan Jun 20 '12 at 16:27
I blindly cut & pasted, thanks for noticing. Fixed. –  skuro Jun 20 '12 at 16:30
Anyway, Why we need Test in the method argument? Without that, it should work..? –  Abimaran Kugathasan Jun 20 '12 at 16:37

So the problem was in


java should start from the small letter. But the bigger problem was that clojure lib didn't want to return java.util.HashMap as an object. The solution is to serialize it and then return.

share|improve this answer

Your Answer


