【问题标题】:Problem Extending A Class in Clojure: ClassFormatError: Duplicate field name&signature在 Clojure 中扩展类的问题:ClassFormatError: Duplicate field name&signature
【发布时间】:2009-10-26 22:39:23
【问题描述】:

我正在尝试使用 Clojure 扩展 JButton,但是当我尝试创建自己的构造函数时遇到了问题。每当我将:constructors:gen-class 一起使用时,当我尝试实例化我的类时,我不断收到“ClassFormatError: Duplicate field name&signature”消息。

认为我正确地关注了Clojure docs。我做错了吗?

例子:

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

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

【问题讨论】:

  • 我得到了同样的结果,但不知道为什么。

标签: oop clojure gen-class


【解决方案1】:

JButton 扩展了 javax.swing.AbstractButton,它已经有一个受保护的 init 方法。如果您将 Clojure-init 函数重命名为,例如,my-init,问题就消失了:

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

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

【讨论】:

    猜你喜欢
    • 2020-09-14
    • 2013-08-23
    • 1970-01-01
    • 2011-05-02
    • 1970-01-01
    • 1970-01-01
    • 2011-06-17
    • 2015-03-26
    • 2017-03-27
    相关资源
    最近更新 更多