根据
JavaDocs,java.lang.Class的newInstance()方法并不打算返回null.
但我的代码似乎证明了相反的情况.为什么?
public Assessment createAssessment() {
Class extends Assessment> assessmentClass = (Class extends Assessment>) assessmentClassDataTable.getRowData();
try {
System.out.println("ASSESSMENTCLASS " + assessmentClass);
// -> 'ASSESSMENTCLASS class my.model.ManualSelectAssessment'
Assessment a = assessmentClass.newInstance();
System.out.println("ASSESSMENT " + a);
// -> 'ASSESSMENT null'
return a;
} catch (Exception e) {
Application.handleError(e);
}
return null;
}
它返回null.