本帖最后由 张先龙 于 2013-4-11 21:36 编辑
public class Test {
public static <Constructer> void main(String[] args) throws ClassNotFoundException, SecurityException, NoSuchMethodException {
String TestClass = null;
// TODO Auto-generated method stub
Constructer con=(Constructer)Class.forName("TestClass").getConstructor(String.class);
TestClass test=(TestClass)con.newInstance("");
}
}
class TestClass{
private String str;
TestClass(String str){
this.str=str;
}
public void printStr(){
System.out.println(str);
}
}
红色的那段代码出错 ,提示的是The method newInstancce(String) is undefined for the type Constructer ,我看了半天也没改过来 哪位同学指点下! |