You can specify the type of return in the protocol
(defprotocol Individual (^Integer age [this]))
and the compiler will execute your methods:
(defrecord person [] Individual (^String age [this] "one")) ; CompilerException java.lang.IllegalArgumentException: Mismatched return type: age, expected: java.lang.Object, had: java.lang.String, ...
But you do not need to follow a hint like:
(defrecord person [] Individual (age [this] "one")) (age (new person)) ; "one"
Does the hint type have any effect?
This continuation Is it possible to specify the type of the returned method in clojure defrecord?
clojure
Thumbnail
source share