views:

215

answers:

1

I'm trying to extend JButton with Clojure, but I ran into a problem when I try to create my own constructors. Whenever I use :constructors with :gen-class I keep getting a "ClassFormatError: Duplicate field name&signature" message when I try to instantiate my class.

I think I'm following the Clojure docs properly. 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])
+1  A: 

JButton extends javax.swing.AbstractButton which already has a protected init method. If you rename your Clojure-init function to, e.g., my-init the problem is gone:

(ns test.gui.button
  (:gen-class
   :extends javax.swing.JButton
   :constructors {[] [String]}
   :init my-init))

(defn -my-init []
  [["Click Me"] nil])
janko