public class ToStringPRU{
public static String tostring(Object o) throws Exception{
Class c=o.getClass();
Field[] fl=c.getDeclaredFields();
String[] s=new String[fl.length];
for (int i = 0; i < s.length; i++) {
s[i]=""+fl[i].get(o);
}
String st ="";
for (int i = 0; i < s.length; i++) {
st+=s[i]+" ";
}
return st;
}
}
转载于:https://my.oschina.net/2892328252/blog/639294
本文提供了一种将Java对象转换为字符串的方法,通过获取对象的所有字段值并拼接成一个字符串返回。这种方法适用于简单的对象展示。

1440

被折叠的 条评论
为什么被折叠?



