I have a set of bean classes. I would like to know the best approach to generate the getters and setters automatically at run time. Can anyone help please.
Asked
Active
Viewed 1.2k times
0
-
Use your IDE's "generate code" function? – The Head Rush Aug 07 '19 at 17:36
-
1Can you please elaborate a bit, what do you mean at run time. is it that when you run your java program you want some other java classes to be automatically filled with its getter and setters. Also try posting some code of what do you have and what you want – Shrikant Havale Aug 07 '19 at 17:37
3 Answers
6
I'm not aware of a way to generate the getters/setters at runtime, but Lombok has annotations that you can add that will generate the getters/setters for you at compile time. It is a pretty seamless experience. Lombok can also generate builder classes, toString, equals/hashCode methods.

Matt Berteaux
- 763
- 4
- 12
1
You can use Lombok which generates getter, setter, toString methods at runtime. It is a powerful and very helpful library. I provide below the link.

Sambit
- 7,625
- 7
- 34
- 65
-
Thank you very much. I will try Lambok and post if successful in doing it. – Tech Learner Aug 08 '19 at 18:22
-1
After you have created the variables in the class, right click, select Source, select Generate Getters and Setters.

Nic
- 1