根据JavaDocs,newInstance()
Method ofjava.lang.Class
不打算返回 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;
}
它返回空值。