The following example will cause a runtime class cast exception. There appears to be no way to add a type annotation of ^long
to a protocol as it will either get a compile time error or a runtime error.
(defprotocol my-protocol-1
(my-func-1 [this value]))
(deftype my-type-1 [x]
my-protocol-1
(my-func-1 [this value]
(* value 2)))
(def z1 (my-type-1. 123))
(println (my-func-1 z1 99)) ;; this works
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defprotocol my-protocol-2
(my-func-2 [this ^long value])) ;; only a type hit has been added
(deftype my-type-2 [x]
my-protocol-2
(my-func-2 [this value]
(* value 2)))
(def z2 (my-type-2. 123))
(println (my-func-2 z2 456)) ;; will cause exception
;; class user$eval180$fn__181$G__171__188 cannot be cast to class clojure.lang.IFn$OLO