I got a lot of entities, 160 to be specific. I need to override toString
method in all of them.
My question is: Is there some shortcut on Intellij or some external tool where I can auto generate toString
method in all of those entities?
Asked
Active
Viewed 6,946 times
6

KiKo
- 1,668
- 7
- 27
- 56
-
You may need to create a plug-in for that. – CrazyCoder Mar 15 '18 at 02:08
-
If you have a base class with ID, create and mod user and timestap, an elementary toString and hashCode can be done in the base class. – Joop Eggen Jun 21 '22 at 09:05
2 Answers
6
In Intellij i supposed it can be done like this :
Open the desired class for editing and do one of the following:
- On the main menu, choose Code | Generate.
- Right-click the editor and choose Generate on the context menu
- Press Alt+Insert.
From the pop-up list that shows up, select toString() option. Generate toString() wizard displays the list of fields in the class.
In eclipse it could be done aswell :
- Right click the editor
- Select Source
- Then Select generate toString().
- Then select all the fields you want.

Karl Alexander
- 351
- 4
- 16
-
2I know how to auto generate toString method.... My question is to apply that method into all my entity classes.. – KiKo Mar 15 '18 at 22:34
-
Stuck with same issue, any idea how its done, I mean for multiple entities ? – KidWithAComputer Sep 14 '18 at 14:25
-
0
A little bit late, but the easiest way is to add Project Lombok to your project and then annotate all the entities with @ToString annotation.
Simple example:
import lombok.ToString;
@ToString
public class Account {
private String id;
private String name;
// standard getters and setters or you can use @Getter and @Setter form lombok too
}
Here is the result when you call the toString method:
Account(id=12345, name=An account)

KiKo
- 1,668
- 7
- 27
- 56