您可以在协议中提示返回类型
(defprotocol Individual
  (^Integer age [this]))
并且编译器将使您的方法符合:
(defrecord person []
  Individual
  (^String age [this] "one"))
; CompilerException java.lang.IllegalArgumentException: Mismatched return type: age, expected: java.lang.Object, had: java.lang.String, ...
但是您不必遵守类型提示:
(defrecord person []
  Individual
  (age [this] "one"))
(age (new person))
; "one"
类型提示有效吗?
clojure ×1