I want to create an IntelliJ Idea template for the toString method using String.format instead of concatenation, StringBuffer , etc.
For example, I have the following object:
public class Foo { private int id; private String name; private List<String> values; }
If I create a toString for all fields by default, Idea will generate:
@Override public String toString() { return "Foo{" + "id=" + id + ", name='" + name + '\'' + ", values=" + values + '}'; }
But I want to generate the following:
@Override public String toString() { return String.format("Foo(id=%d, name=%s, values=%s)", id, name, values); }
source share