this code doesn\'t compile. I\'m wondering what I am doing wrong:
private static Importable getRightInstance(String s) throws Exception {
Class
where Importable is an interface and the string s is the name of an implementing class.
The compiler can't know that, hence the error.
Use a cast. It is easier to cast the constructed object (because that is a checked cast), than the class object itself.
Class> c = Class.forName(s);
Importable i = (Importable) c.newInstance();
return i;