public static void copy(Object source, Object dest)
{
Method s[] = source.getClass().getMethods();
Method d[] = dest.getClass().getMethods();
try
{
for (int i = 0; i < d.length; i++)
{
String dname = d[i].getName();
String dformat = dname.substring(3);
if (dname.startsWith("set"))
{
for (int j = 0; j < s.length; j++)
{
String sname = s[j].getName();
String sformat = sname.substring(3);
if
(sname.startsWith("get") && sformat.equals(dformat))
{
Object value = null;
value = s[j].invoke(source);
Object[] args = new Object[1];
args[0] = value;
d[i].invoke(dest, args);
}
}
}
}
}
catch (IllegalAccessException e)
{
log.debug(e.getMessage(),e);
// TODO
}
catch (InvocationTargetException e)
{
// TODO
}
}
java对象属性复制
最新推荐文章于 2024-07-24 17:33:46 发布