public static <T>void testRef(Class<T> clazz) throws Exception{
T obj = clazz.newInstance();
Field[] fields = clazz.getDeclaredFields();
for(Field field : fields){
PropertyDescriptor descriptor = new PropertyDescriptor(field.getName(), clazz);
Method method = descriptor.getWriteMethod();
System.out.println(method.getName());
method.invoke(obj, "12");
}
}
public static void main(String[] args) throws Exception {
String s = "desc";
System.out.println("set" + (s.toUpperCase().charAt(0)) + s.substring(1));
testRef(A.class);
}
<pre name="code" class="java">class A {
private String name;
private String desc;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDesc() {
return desc;
}
public void setDesc(String desc) {
this.desc = desc;
}
public A() {
super();
}
}