似乎当您为"[Ljava.lang.Object;"扩展协议时,分派无法解析"[Ljava.lang.Object;"的子类型。
(defprotocol Table
(t [this]))
(extend-protocol Table
(Class/forName "[Ljava.lang.Object;")
(t [this] this))
(t (make-array java.lang.String 0))
=> IllegalArgumentException No implementation of method: :t of protocol: #'test-t/Table found for class: [Ljava.lang.String; clojure.core/-cache-protocol-fn (core_deftype.clj:568)
(t (make-array java.lang.Object 0))
=> ["[Ljava.lang.Object;" 1512480936 "[Ljava.lang.Object;@5a26a0a8"]
然而,Java在Object[]上是协变的。
(instance? (Class/forName "[Ljava.lang.Object;") (make-array java.lang.String 0))
=> true
$ cat > Foo.java
public class Foo {
public Object[] fooey;
public Foo() {
fooey = new String[10];
}
}
$ javac Foo.java
$