记录可以在不实现协议的任何方法的情况下实现协议:
(defprotocol Structure
(weight [this])
(balanced? [this]))
(defrecord Mobile []
Structure
)
...被接受。
如果您尝试使用不存在的方法:
(balanced? (Mobile.))
;java.lang.AbstractMethodError: user.Mobile.balanced_QMARK_()Ljava/lang/Object;
像往常一样,在运行时会发现类型错误。