【问题标题】:Can gen-class override a protected Java method?gen-class 可以覆盖受保护的 Java 方法吗?
【发布时间】:2013-05-28 17:36:09
【问题描述】:

我正在尝试使用 Clojure 中的 Swing,但我对 gen-class 感到困惑,我无法从文档中判断这是否应该工作 - paintComponentJPanel 上的受保护方法,并且我可以覆盖它,但是当我尝试调用暴露的超类的方法时,我得到 java.lang.IllegalArgumentException: No matching method found: parentPaintComponent for class project.PicturePanel 。谁能澄清为什么我似乎无法使用此方法?

(ns project.PicturePanel
  (:gen-class
    :extends javax.swing.JPanel
    :name project.PicturePanel
    :exposes-methods {paintComponent parentPaintComponent}))

(defn -paintComponent [this g]
  (println this)
  (println g)
  (.parentPaintComponent this g))

【问题讨论】:

  • 你知道跷跷板吗? github.com/daveray/seesaw
  • 我会试试跷跷板,但我肯定想更好地了解 Java 互操作的东西。
  • 嗯,我刚刚对此进行了测试,它对我来说效果很好。您能否提供有关您的项目设置和调用代码的更多详细信息?你用过 AOT 编译吗?
  • A.韦伯 - 感谢您的提示!事实证明,“lein run”并没有重新编译这个类,所以我处于一个有趣的状态,新的 paintComponent 方法正在被解释,但该类的其余部分是一个旧的、过时的二进制文件。在我重新运行“lein compile project.PicturePanel”之后,事情开始工作了!

标签: clojure gen-class


【解决方案1】:

是的!如果您确保编译的 .class 文件是最新的,则代码可以正常工作。尝试重新编译它们!

【讨论】:

    猜你喜欢
    • 2011-08-04
    • 2013-07-01
    • 2015-10-01
    • 2019-02-13
    • 1970-01-01
    • 1970-01-01
    • 2022-07-08
    • 2012-01-26
    相关资源
    最近更新 更多