/ Published in: Java
Surprisingly often I want to print all the values of some object for debugging reasons, and if the object has a lot of different get methods (and toString is not good for this), it is a pain to write all the print commands. That's when this snippet is useful (yes, it is not perfect, and if get methods are not named as "getXXX", it does not find those, but it is your own fault then).
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
try { if (m.getName().startsWith("get") && m.getReturnType() != void.class && m.getParameterTypes().length == 0) { } e.printStackTrace(); } }