日期:2014-05-20 浏览次数:20706 次
public static void setter(Object obj,String att,Object value,Class<?>type){
try{
Method met = obj.getClass().getMethod("set"+initStr(att),type);
met.invoke(obj, value);
}catch(Exception e){
e.printStackTrace();
}
}
public static void getter(Object obj,String att){
try{
Method met = obj.getClass().getMethod("get"+initStr(att));
System.out.println(met.invoke(obj));
}catch(Exception e){
e.printStackTrace();
}
return temp;
}
public static Object getter(Object obj,String att){
try{
Method met = obj.getClass().getMethod("get"+initStr(att));
Object temp = met.invoke(obj);
}catch(Exception e){
e.printStackTrace();
}
return temp;
}
try{
Method met = obj.getClass().getMethod("get"+initStr(att));
Object temp = met.invoke(obj);
}catch(Exception e){
e.printStackTrace();
}
return temp;
改为
Object temp=null;
try{
Method met = obj.getClass().getMethod("get"+initStr(att));
temp = met.invoke(obj);//这里定义是局部变量,return娶不到的。
}catch(Exception e){
e.printStackTrace();
}