I have a simple jar file containing class A
:
public class A {}
Then I load it in runtime:
var classLoader = new URLClassLoader(Array(my_jar_file.toURI.toURL))
var clazz = classLoader.loadClass("A")
It is ok, it can load the class A
. This command is also ok:
clazz.newInstance
But when I cast it to A
:
clazz.newInstance.asInstanceOf[A]
I got this error:
java.lang.ClassCastException: A cannot be cast to A
Could you please help me?