POSTS

Java - Reflection dynamic toString() method

<![CDATA[ @Override public String toString() { StringBuilder sb = new StringBuilder(); String value; sb.append(super.getClass().getName()); sb.append(”: “); sb.append(super.toString()); sb.append(getClass().getName()); sb.append(”: “); for (java.lang.reflect.Field f : Width.class.getDeclaredFields()) { try { value = f.get(this).toString(); sb.append(f.getName()); sb.append(“=”); sb.append(value); sb.append(“, “); } catch (Exception e) { } } return sb.toString(); } ]]>
SyntaxHighlighter.highlight();