18 August 2009

Auto-generate Java getter/setter methods in Eclipse

The Eclipse IDE is a powerful tool for Java development. One feature I just discovered: How to automatically generate getter/setter methods (properties) for your classes.

In your class, place your cursor on a private member, and you'll notice a yellow underline and a little popup with options. One of them is "Create getter and setter for 'myPrivateVariable'". Simply click this choice and Eclipse displays a dialog to choose getter and setter method names as well as other options. You can also access this getter/setter auto-generate functionality by placing your cursor on a private field and then going to Refactor > Encapsulate Field.

1 comment:

Prathap said...

thanks very much for sharing the tip.