The following method is to implement toString
public String toString() {
return ReflectionToStringBuilder.toString(this);
}
How to understand the parameter this
used by toString
, what does it stand for here? Besides, why do we need to implement toString
this way?
ReflectionToStringBuilder
is a utility class used to generate theString
returned when overridingObject#toString
using the fields of the class instance passed as an argument.this
here refers to current instance of theObject
whose fields are used to generate the returnedString
The main advantage to using this class is that the
String
does not have to be generated every time fields are added or removed.