I want to send class data through the Scala RemoteActor API. I made a custom ClassLoader but it has trouble loading the class [B. I have found out that it represents byte[] in Java. How could I handle this problem? Here is the loadClass method of my ClassLoader.
override def loadClass(name: String): Class[_] = {
if(ClientEntry.verbose) println("loadClass "+name)
var c = findLoadedClass(name)
if (c == null) {
try {
c = findSystemClass(name)
} catch { case _ => null}
}
if (c == null) {
try {
c = defaultloader.loadClass(name)
} catch {
case _ => c = loadRemoteClass(name)
}
}
resolveClass(c)
c
}
The java class
byte[]is synonymous withArray[Byte]so if you encounter a class named"[B"then one could simply get the class directlyclassOf[Array[Byte]]since is a primitive of the language.Unfortunately, things are more complicated than that. There are more java array primitives that need to be handled as well. See how the following classes are named.
Notice the type erasure on the last one. And also nested arrays need to be handled as well.