Java ClassCastException MyType不能强制转换为MyType?

Java ClassCastException MyType不能强制转换为MyType?,java,clojure,jvm,clojure-java-interop,counterclockwise,Java,Clojure,Jvm,Clojure Java Interop,Counterclockwise,我在Clojure中使用deftype时遇到了一个问题。如果我运行以下代码: (defprotocol TestProt (geta [this]) (getb [this])) (deftype TestType [a b] TestProt (geta [this] a) (getb [this] b)) (defn test-function [^TestType a-testtype] (print (.geta a-testtype))) (def te

我在Clojure中使用deftype时遇到了一个问题。如果我运行以下代码:

(defprotocol TestProt
  (geta [this])
  (getb [this]))

(deftype TestType [a b]
  TestProt
  (geta [this] a)
  (getb [this] b))

(defn test-function [^TestType a-testtype]
  (print (.geta a-testtype))) 

(def test-tt (TestType. 1 1))

(test-function test-tt)
然后编译器抛出:ClassCastException MyProject.core.TestType不能强制转换为MyProject.core.TestType。我做错了什么,还是这是一个错误?请注意,如果我从测试函数中删除类型注释,那么它只是:

(defn test-function [a-testtype]
  (print (.geta a-testtype))) 
然后代码就可以正常工作了,但是我得到了一个关于反射的警告(启用了反射上的警告),它运行得比较慢,这违背了在我当前用例中使用deftype的目的


Edit:好的,代码在repl中工作,但在我使用ctrl-alt-s加载它时不工作(我在Eclipse中通过逆时针方向运行它)。因此,Eclipse或逆时针方向似乎是问题所在。

当您重新定义一个类型(使用
deftype
defrecord
)时,就会发生这种情况,但在某个地方使用了以前存在的类,在类型提示中就是这样

我无法重现您用Counterclockwise的CtrlAltS描述的行为,但它确实在一个新的REPL中评估了以下表达式,因此它可能会以某种方式帮助诊断您的具体情况

(defprotocol TestProt
(格塔[这个])
(getb[this]))
(deftype TestType[a b]
测试保护
(geta[这个]a)
(getb[这个]b)
(defn测试函数[^TestType a-TestType]
(打印(.geta-testtype)))
(def测试tt(测试类型1)
(println:first(测试功能测试tt))
;= :前1
;; 重新定义类型。。。
(deftype TestType[a b]
测试保护
(geta[这个]a)
(getb[这个]b)
;; ...并用新版本测试tt-var
(def测试tt(测试类型1)
(println:second(测试功能测试tt))
;= ClassCastException user.TestType无法强制转换为user.TestType用户/测试函数(无源文件:89)

在我这方面不可复制。Clojure 1.5.1Me也是。不可复制。Clojure 1.5.1我也在运行1.5.1,但在Eclipse中,通过逆时针方向加载core.typed。我刚刚尝试了repl,它在那里工作,只是在我用ctrl-alt-s加载代码时不起作用。