How to Instance and reference a class by its name????
Hi guys. I got a problem here. How can I get an instance of a specific class having the class name and casting it to the correct class type. I know that using the Class.forName("className").newInstance () will do the trick.
But the problem is that the newInstance () method returns an Object and I need to have a reference to the specific class. The className is read from a database and I need to execute a method from that class.
public void execute (String className, ArrayList params) {
Class.forName (className).newInstance ();
........
}
now lets suposse className = "package.Validator"
and I need to execute Validator.validate(params) but as I get an Object I cant execute the validate method.
I cannot do a cast like (Validator)Class.forName (className).newInstance ();
becausse the classname is dinamyc.
Thanks in advance.:confused: