简体   繁体   English

gen类可以覆盖受保护的Java方法吗?

[英]Can gen-class override a protected Java method?

I'm trying to use Swing from Clojure, and I'm getting confused by gen-class and I can't tell from the documentation if this is supposed to work - paintComponent is a protected method on JPanel , and I'm able to override it, but when I try to call the exposed superclass's method, I get java.lang.IllegalArgumentException: No matching method found: parentPaintComponent for class project.PicturePanel . 我试图使用Swing从Clojure的,而且我越来越迷茫了gen-class ,如果这应该是工作,我无法从文件告诉我们- paintComponent是一个受保护的方法JPanel ,我能覆盖它,但当我尝试调用暴露的超类的方法时,我得到java.lang.IllegalArgumentException: No matching method found: parentPaintComponent for class project.PicturePanel Can anyone clarify why I don't seem to have access to this method? 任何人都可以澄清为什么我似乎无法访问此方法?

(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))

Yes! 是! The code works correctly if you make sure that your compiled .class files are up to date. 如果您确保已编译的.class文件是最新的,则代码可以正常工作。 Try recompiling them! 尝试重新编译它们!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM