Hi guys, I am wondering why this does not work:

(.containsKey {:one 1} :one)
;=> ClassCastException clojure.lang.PersistentArrayMap cannot be cast to
clojure.lang.PersistentHashMap

The map is a:

(class {:one 1})
;=> clojure.lang.PersistentArrayMap

And a PersistentArrayMap does have a containsKey method (
https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/PersistentArrayMap.java#L95
).

I can even find the method:

(filter #(= "containsKey" (.getName %)) (.getMethods (class {:one 1})))
;=> (#<Method public boolean
clojure.lang.PersistentArrayMap.containsKey(java.lang.Object)>)

Should this not be a normal reflective method lookup, why do I get a
ClassCastException?

It does work if the map gets big enough:

(.containsKey {1 1, 2 2, 3 3, 4 4, 5 5, 6 6, 7 7, 8 8, 9 9} 1)
;=> true

But at this point its a different collection:

(class {1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9})
;=> clojure.lang.PersistentHashMap

Cheers,
Alf

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to