Problem Class Extension in Clojure: ClassFormatError: Duplicate Field Name and Signature

I am trying to extend JButton with Clojure, but I have a problem when I try to create my own constructors. Whenever I use :constructors with :gen-class , I get the message "ClassFormatError: Duplicate field name & signature" when I try to instantiate the class.

I think I follow the Clojure docs correctly. Am I doing something wrong?

Example:

 (ns test.gui.button (:gen-class :extends javax.swing.JButton :constructors {[] [String]} :init init)) (defn -init [] [["Click Me"] nil]) 
+4
source share
1 answer

JButton extends javax.swing.AbstractButton , which already has a protected init method. If you rename your Clojure -init function, for example, my-init , the problem goes away:

 (ns test.gui.button (:gen-class :extends javax.swing.JButton :constructors {[] [String]} :init my-init)) (defn -my-init [] [["Click Me"] nil]) 
+6
source

All Articles