Welcome! Please see the About page for a little more info on how this works.

0 votes
in Protocols by
It appears that when you extend a protocol for "[Ljava.lang.Object;", the dispatch can not resolve for child types of "[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"]


Yet Java is covariant on 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
$

2 Answers

0 votes
by

Comment made by: alexmiller

Related: CLJ-1381

0 votes
by
Reference: https://clojure.atlassian.net/browse/CLJ-2215 (reported by alex+import)
...