Search code examples
javaeclipseidegetter-setter

Autogeneration of Get & Set methods in Java?


I think the creation of holder classes, classes with just attritutes, get methods and set methods can be autogenerated.

I understand that Eclipse is a defacto "standard" Java IDE these days.
Does Eclipse do this?
Do other IDEs?

I'm guessing the only reasons for making dedicated data holding classes instead of using HashMaps is to have mixed datatypes in a more visible/safter way and for the occasion when you want to DO something to the data when inserting it or retrieving it. Thoughts?


Solution

  • Yes. Eclipse Does this. To generate setter/getter, select the class in package explorer, right click -> Source -> Generate getter/setting.

    Netbean also does this. Right click anywhere inside your class -> insert code-> setter/getter.

    we do that to encapsulate the implementation details. you can find more explanations Why use getters and setters