50,343
社区成员




public String set(Object obj,String fieldname,Object value)
{
String valuetype=value.getClass().getName();
try {
Field field=obj.getClass().getDeclaredField(fieldname);
String totype=field.getType().getSimpleName();
if (typeTransferok(valuetype,totype)==false)
return "type cannot be converted from "+valuetype+" to "+totype;
field.setAccessible(true);
Object typedvalue=value;
if (ballowFloatToInt&&(value instanceof Float||value instanceof Double))
{
typedvalue=Math.floor((double) value);
}
field.set(obj, typedvalue);
//if run failed, will not return null
return null;
} catch (NoSuchFieldException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return "error";
}
我现在封装了单个的