如何从“ id = (PK) m.invoke(obj, (Object []) null);
”中删除警告
private PK getId(T obj) {
PK id = null;
for (Field f : type.getDeclaredFields()) {
if (f.getAnnotation(Id.class) != null) {
String name = f.getName();
String method = "get" + name.substring(0, 1).toUpperCase() + name.substring(1);
try {
Method m = type.getDeclaredMethod(method, (Class<?>) null);
id = (PK) m.invoke(obj, (Object []) null);
} catch (Exception e) {
e.printStackTrace();
}
}
}
return id;
}