Issue
Recently we moved to IntelliJ and using it for JAVA, earlier we were using Eclipse, we are able to configure the IntelliJ code format setting same as Eclipse except for toString()
.
toString()
output in POJO is very different from eclipse as shown below,
toString()
in IntelliJ
@Override
public String toString() {
return "Entity{" +
"entityName='" + entityName + '\'' +
", isBaseEntity=" + isBaseEntity +
", entityAttribute=" + entityAttribute +
'}';
}
toString()
in Eclipse
@Override
public String toString() {
return "Entity [entityName=" + entityName + ", isBaseEntity=" + isBaseEntity
+ ", entityAttribute=" + entityAttribute;
}
Question
Is there any way/setting through which I can make IntelliJ toString()
same as eclipse?
Solution
Code > Generate... > toString()
On the dialog that opens, in the top right, there is a button labelled 'Settings...'. You can specify a template. There are 11 default templates. You can add your own to generate whatever you want.
Better yet, use Lombok to generate your toString
. It's opinionated about the format, but I much prefer that to having my code littered with boilerplate. It also automatically updates if you add a field to the class, which an IDE generated method will not do.
Answered By - Michael