Help kindly requested
Is there a way in Java that I can determine the type class of an Object returned by the loadClass() method of a ClassLoader. The reason for this is I need to cast the returned Object dynamically to its type without needing to hard-code it first because at some situations, you'd never know what type of class you'd be dealing with.
Below is an example situation:
ClassLoader classLoader = this.getClass().getClassLoader();
Class anyClass = classLoader.loadClass("aymanClass");
// the following line is where I need to know the type 'aymanClass' dynamically instead of hard-coding it as it's shown below:
Object x = (aymanClass) anyClass.newInstance();
//I was dreaming of something like this:
Type t = anyClass.getType();
Object x = (t) anyClass.newInstance();
I don't know if there's something similar in Java or just a work-around?
Thanks and regards,