我正在使用gen-class编写一个Clojure类。我在下面的代码中有一个试图访问的"state“字段:
(ns com.example.sparetime.DateButton
(:gen-class
:extends javax.swing.JToggleButton
:init initialize
:state state
:constructors {[Integer] [String]})
(:import
[java.awt Insets]))
(if *compile-files*
(set! *warn-on-reflection* true))
(def insets (Insets. 1 1 1 1))
(defn -initialize [day-number]
[[(Integer/toString day-number)] day-number])
(defn get-day-number [this]
(.state this))
(defn -getInsets [this]
insets)我在包含(.state this)的行上收到反射警告。我尝试使用(.state ^DateButton this)添加类型提示,但随后得到一个编译错误,指出编译器无法解析DateButton (鸡和蛋?直到编译器编译完这个文件,Datebutton才会存在)。
请不要在意提示这段代码的类型的智慧。我该怎么做呢?我需要完全限定DateButton包吗?
发布于 2011-07-11 15:11:28
您必须导入您的类或完全限定其名称。然后^DateButton提示将起作用并消除反射。
https://stackoverflow.com/questions/6625104
复制相似问题