开发者

Clojure throws ClassCastException on java.util.Collection

开发者 https://www.devze.com 2023-01-27 04:07 出处:网络
I\'m trying to use an MPD library in Java in Clojure. Everything has gone well, but these methods that return a java.util.Collection get bad reception in REPL. Let\'s define

I'm trying to use an MPD library in Java in Clojure. Everything has gone well, but these methods that return a java.util.Collection get bad reception in REPL. Let's define

(def mpd (org.bff.javampd.MPD. "localhost" ))
(def pl (.getMPDPlaylist mpd))
(def db (.getMPDDatabase mpd))

And now some methods play ok:

(.getSongList pl) ; returns List<MPDSong>

works well. But for instance every db (MPDDatabase) method return Collection<MPDSong> (according to their API):

(.findAlbum db "Crises") ; returns Collection<MPDSong>
java.lang.ClassCastException (NO_SOURCE_FILE:0)

Doesn't work that well. Why is that, how to fix it?

Stack trace follows:

hello.hello=> (.findAlbum db "Crises")
java.lang.ClassCastException (NO_SOURCE_FILE:0)
hello.hello=> (.printStackTrace *e)
java.lang.ClassCastException (NO_SOURCE_FILE:0)
    at clojure.lang.Compiler.eval(Compiler.java:5440)
    at clojure.lang.Compiler.eval(Compiler.java:5391)
    at clojure.core$eval.invoke(core.clj:2382)
    at clojure.main$repl$read_eval_print__5624.invoke(main.clj:183)
    at clojure.main$repl$fn__5629.invoke(main.clj:204)
    at clojure.main$repl.doInvoke(main.clj:204)
    at clojure.lang.RestFn.invoke(RestFn.java:422)
    at user$eval13$acc__808__auto____14$fn__16.invoke(NO_SOURCE_FILE:1)
    at clojure.lang.AFn.run(AFn.java:24)
    at java.lang.Thread.run(Thread.java:662)
Caused by:开发者_运维技巧 java.lang.ClassCastException
    at java.lang.Class.cast(Class.java:2990)
    at clojure.lang.Reflector.boxArg(Reflector.java:364)
    at clojure.lang.Reflector.boxArgs(Reflector.java:397)
    at clojure.lang.Reflector.invokeMatchingMethod(Reflector.java:55)
    at clojure.lang.Reflector.invokeInstanceMethod(Reflector.java:28)
    at hello.hello$eval44.invoke(NO_SOURCE_FILE:8)
    at clojure.lang.Compiler.eval(Compiler.java:5424)
    ... 9 more
nil


Looks like the API Documentation is invalid (checking using clojure.contrib.repl-utils):

user> (show MPDDatabase "findAlbum$")
===  public org.bff.javampd.MPDDatabase  ===
[ 1] findAlbum : Collection (MPDAlbum)

and you need to a intermediate MPDAlbum object:

user> (.findAlbum db (MPDAlbum. "Crisis"))
#<ArrayList []>
0

精彩评论

暂无评论...
验证码 换一张
取 消