我在 repl 中玩协议时遇到了以下情况
(defprotocol IGreeter
(greet [this]))
(deftype MyGreeter []
IGreeter
(greet [_] "hi from MyGreeter"))
(extends? IGreeter MyGreeter)
;=> true
;; I expected to see MyGreeter listed here, but result is nil
(extenders IGreeter)
;=> nil
现在将协议扩展到一些类型。
(extend-protocol IGreeter
String
(greet [this] "hi-string")
clojure.lang.Symbol
(greet [this] 'hi-sym) ; ' help syntax highlighter
clojure.lang.Keyword
(greet [this] :hi-kw))
(extenders IGreeter)
;=> (java.lang.String clojure.lang.Symbol clojure.lang.Keyword)
String、Symbol 和 Keyword 显示为 IGreeter 的扩展器。MyGreeter 不。这尤其令人惊讶,因为 (extends? IGreeter MyGreeter) 返回 true。我是不是理解错了,或者是bug吗?谢谢!