以下为有效的Clojure代码(关注extend-type (class (log-window-proxy nil))
,而不是引用类字面量)
(defn- log-window-proxy [state]
(proxy [javax.swing.JTextArea clojure.lang.IDeref] []
(deref [] state)
(scrollRectToVisible [rect]
(if @(:auto-scroll? state)
(proxy-super scrollRectToVisible rect)))))
(defprotocol LogWindow
(log [this message])
(clear [this]))
(extend-type (class (log-window-proxy nil))
LogWindow
(log [this message]
(println "message" message))
(clear [this]
nil))
然而,当您检查给定的this
的::tag元数据时,它似乎以一种有些奇怪的形式存在(因为它仍然是一系列调用,而不是类字面量)
(-> (extend-type (class (log-window-proxy nil))
LogWindow
(log [this message]
(println "message" message))
(clear [this]
nil)) quote macroexpand last :log second ffirst meta)
;; => {:tag (class (log-window-proxy nil))}
因此,:tag看起来像是一个函数调用。编译器最终是否会调用(class (log-window-proxy ...
)以获取一个它可以实际用作类型提示的类?
否则我担心这个:tag元数据是无效的,这可能会引起反射警告,并可能使第三方工具产生混淆。