The toString method was generated in eclipse as follows :
StringBuilder builder = new StringBuilder();
builder.append("Person [");
if (firstName != null)
builder.append("firstName=").append(firstName).append(", ");
if (lastName != null)
builder.append("lastName=").append(lastName).
if (title != null)
builder.append("title=").append(title).append(", ");
if (car != null)
builder.append("car=").append(car).append(", ");
builder.append("]");
Why didn't they use more short form e.g.
builder.append("firstName=" + firstName + ", ");
Is it to save time with String creation?
How do I change template to this format ?
${object.className} [${member.name()}=${member.value}, ${otherMembers}]
The first form is ever so slightly faster - in the other forms additional StringBuilder are created within the byte code. In general this does not matter much unless string creation is performed in a tight loop.
As for the second question, what have you tried?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With