Heefoo
Heefoo

Reputation: 125

Problem overwritting java method from clojure

I am desperetly trying to create a class that with a "toString" method from clojure According to clojure docs the following should work:

(ns override-test.simpleClass
   (:gen-class
     :name         simpleClass
     :methods      [[^{Override {}}  toString [] String]]
     :state        state
     :init         init
     :constructors {[String] []}))
(defn -init
  [name_]
  [[] (atom name_)])
(defn -toString [this]
  (deref (.state this)))

However evaluating (simpleClass. "test") Throws
CompilerException java.lang.ClassFormatError: Duplicate method name "toString" with signature "()Ljava.lang.String;" in class file simpleClass, compiling:(override_test/simpleClass.clj:19:3) Any incites of what i might be doing wrong ?

Upvotes: 0

Views: 151

Answers (1)

Heefoo
Heefoo

Reputation: 125

As Biped Phill mentioned the problem was that toString seems to be already implemented by virtue of the automatic subclassing mechanism of gen-class. Probably Ljava.lang. String is treated as a (?) superclass and toString is added automatically, so i just had to remove it from :methods which is for not inherited methods and it worked like a charm.

Upvotes: 1

Related Questions