I'm Using gen-class to generate Java-classes from my Clojure code. In order to make gen-class work, I need to add an additional first parameter to all methods that will be added to the class (here called this
).
(ns com.stackoverflow.clojure.testGenClass
(:gen-class
:name com.stackoverflow.clojure.TestGenClass
:implements [com.stackoverflow.clojure.TestGenClassInterface]
:prefix "java-"))
(def ^:private pre "START: ")
(defn java-addToString [this text post]
(str pre text post))
After compilation, calling the method in a Java-context works fine.
(def var (com.stackoverflow.clojure.TestGenClass.))
(.addToString var "Aus Clojure heraus (Methode 1)." " :ENDE")
(. var addToString "Aus Clojure heraus (Methode 2)." " :ENDE")
But how can I start it directly from Clojure?
Thge following does not work, since the first parameter is missing.
(java-addToString "TexT" " :END")
Is it good practice to simply call the function with an empty first parameter?
(java-addToString "" "TexT" " :END")
Or should I add a function (e.g. addToString
) that I use internally and call this function from the one that will be added as a method to the class-file?