On Tue, Oct 27, 2009 at 1:01 AM, Cristian <super.sgt.pep...@gmail.com> wrote: > > I tried overloading -init, but I get the same problem. > > java.lang.ClassFormatError: Duplicate field name&signature in class > file test/gui/button (repl-1:2) > > e.g.: > > (ns test.gui.button > (:gen-class > :extends javax.swing.JButton > :constructors {[] [String]} > :init init)) > > (defn -init > ([] [["Click me"] nil]) > ([one-arg] [["Click me"] nil]))
I'm not sure what the problem is -- it may be a bug in gen-class, since the error appears as soon as an :init is specified on this class: (ns test.gui.button (:gen-class :init init)) And you don't even need to run any user-supplied code to trigger it, just mention the class at the REPL: user=> test.gui.button java.lang.ClassFormatError: Duplicate field name&signature in class file test/gui/button (NO_SOURCE_FILE:0) Fortunately you probably don't need gen-class at all for what you're trying to do. Actually, I'm not sure why you'd need to derive from JButton at all; usually it's enough to make one: (defn click-me-button [] (javax.swing.JButton. "Click me")) But if you really want to change the behavior, you can often use 'proxy' instead: (def gui-button (let [ctor (fn [text] (proxy [javax.swing.JButton] [text] (doClick [] (println "my own doClick"))))] (fn ([] (ctor "Click me")) ([one-arg] (ctor "Click me"))))) user=> (.doClick (gui-button)) my own doClick Hope that helps, --Chouser --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~----------~----~----~----~------~----~------~--~---