实例化泛型类给出编译时错误:“无法直接实例化”
public synchronized <T extends Persistable> T read(Class<T> clazz) {
T temp;
try {
if(cache.containsKey(clazz)){
return (T)cache.get(clazz);
}else{
Properties properties = getProperties();
temp = internalFileManager.read(clazz, properties.getProperty(clazz.getSimpleName()));
if(temp == null){
temp = new T();///cannot be instantiated directly
}
cache.put(clazz,temp);
return temp;
}
} catch (Exception e) {
Log.e("","",e);
return null;
}
}
这是问题,所以 new T() 和 new Class() 都不起作用,它可能只是简单的解决方案,只需要一些提示。