Apache commons-lang ReflectionToStringBuilder does this for you.
import org.apache.commons.lang3.builder.ReflectionToStringBuilder
// your code goes here
public String toString() {
return ReflectionToStringBuilder.toString(this);
}
More Related Contents:
- Java Reflection Performance
- Faster alternatives to Java’s reflection [closed]
- Dumping a java object’s properties
- Java Reflection: Why is it so slow?
- Why is reflection slow?
- How can I improve performance of Field.set (perhap using MethodHandles)?
- When to use StringBuilder in Java [duplicate]
- The performance impact of using instanceof in Java
- Fastest way to iterate over all the chars in a String
- How do I speed up the gwt compiler?
- The connection between ‘System.out.println()’ and ‘toString()’ in Java
- Can I get information about the local variables using Java reflection?
- Performance of StringTokenizer class vs. String.split method in Java
- Is there any performance reason to declare method parameters final in Java?
- Why is System.out.println so slow?
- Android RecyclerView Scrolling Performance
- Java HashMap performance optimization / alternative
- Does variable = null set it for garbage collection
- JTable Calls Custom Cell Renderer Method… Continuously
- Java reflection: how to get field value from an object, not knowing its class
- Set field value with reflection
- fastest (low latency) method for Inter Process Communication between Java and C/C++
- How to speed up Java VM (JVM) startup time?
- Java: how much time does an empty loop use?
- Proguard and reflection in Android
- Java reflection – impact of setAccessible(true)
- How do I iterate over class members?
- How to get all imports defined in a class using java reflection?
- What GC parameters is a JVM running with?
- How to watch a variable for changes