我希望我的程序在原始类型及其包装类之间表现不同,例如:
(defmulti try-type class)
(defmethod try-type Integer [arg]
(println "Integer"))
(defmethod try-type Integer/TYPE [arg]
(println "int"))
但它不起作用,虽然我尝试 Integer 和 int 两者
user=> (try-type (.intValue (int 2)))
Integer
nil
user=> (try-type (int 2))
Integer
nil
那么,是否可以在原始类型上调度多方法?
======编辑======
我正在将 google guava 包装到 clojure 中。其中有一个原始库,例如布尔值、Dobules、Ints 等。它们有一些共同的方法,所以我想尝试多方法。