Java class Class<T> and static method Class.forName() drive me crazy.
Posted
by matt
on Stack Overflow
See other posts from Stack Overflow
or by matt
Published on 2010-05-23T18:06:16Z
Indexed on
2010/05/23
18:11 UTC
Read the original article
Hit count: 251
Hi, this code doesn't compile. i'm wandering what i am doing wrong:
private static Importable getRightInstance(String s) throws Exception {
Class<Importable> c = Class.forName(s);
Importable i = c.newInstance();
return i;
}
where Importable is an interface and the string s is the name of an implementing class. The compiler says:
./Importer.java:33: incompatible types
found : java.lang.Class<capture#964 of ?>
required: java.lang.Class<Importable>
Class<Importable> c = Class.forName(format(s));
thanks for any help!
© Stack Overflow or respective owner