使用 Class.forName() 通过类名获取类
public static Class<?> getClazz(String clazzName){
try {
return Class.forName(clazzName);
} catch (ClassNotFoundException e) {
log.error(e.getMessage());
return null;
}
}
可应用于:
// JSON.parseObject(String text, Class<T> clazz)
List<T> res = new ArrayList<>(hits.length);
for (SearchHit hit : hits) {
res.add(JSON.parseObject(hit.getSourceAsString(), c));
}