just searched everywhere. How do I create a new instance from String(name of the class) and return this instance? There indeed are answers yet they didn't answer how could I cast this instance to the type I want. For instance:
class ABC
{
//some code
}
Now I want to create an instance using the name of the class "ABC"(Identical to val abc = new ABC()).
val mirror = universe.runtimeMirror(getClass.getClassLoader);
val classInstance = Class.forName("ABC");
val classSymbol = mirror.classSymbol(classInstance);
val classType = classSymbol.toType;//println(classType) gives ABC
/******this line does not work*****/
classInstance.newInstance().asInstanceOf[classType];
// not asInstanceOf[ABC]
/***********/
Because classInstance.newInstance() has type "Any", how could I convert it to the type "ABC"? Thank you!