I have
trait T
class C extends T
compiled to .class files. And the piece of code below to load them:
val loader = ScalaClassLoader fromURLs (/* List[URL] */)
val classB = loader.tryToInitializeClass("B") getOrElse (/* throw something */)
println(classB.asInstanceOf[Class[_]].getInterfaces)
When I run the loading code in Scala interpreter, the result is
res1: Array[java.lang.Class[_]] = Array(interface T, interface scala.ScalaObject)
but when the loading code compiled into .class files and run I got
[Ljava.lang.Class;@1b8e059
Please tell me how to have the compiled loading code yield the result as fine as on the interpreter.
Are you sure you executed the println in the interpreted session? Because the first result you write looks suspiciously like the interpreter displaying the result of just
classB.asInstanceOf[Class[_]].getInterfaces), without the println (res1 is very telling)On the other hand, the cryptic [Ljava.lang.Class;@1b8e059 is the toString of an Array. So your problem is just that, toString. If you do something like
println(yourResult.mkString(", ")), that should be much better. In the REPL, results displays are better than plain toString