NetBeans Quick Tip #2 - Generating Getters and Setters
Somebody has asked recently on of the mailling lists how to generate getters and setters in NetBeans. I've mentioned that some people even thought NetBeans doesn't have that functionality! So yes, it exists, only it's disguised as "Encapsulate Fields".
You can invoke the action either from the context menu in editor or from the main menu. In both cases use Refactor | Encapsulate Fields. The following dialog pops up and it lets you create getters and setters for all fields in the class:
The good news is that generating getters and setters will be available through the code completion in next release, which will make this feature much more discoverable:
Posted by Valère Déjardin on květen 26, 2005 at 09:07 dop. CEST #
Posted by Jamie Lawrence on květen 26, 2005 at 11:11 dop. CEST #
To Jamie: yes and it works already this way in the experimental version from which I made the screenshot. Only non-existing getters/setters appear as options.
Posted by Roman Strobl on květen 26, 2005 at 11:31 dop. CEST #
Posted by Valère Déjardin on květen 26, 2005 at 05:21 odp. CEST #
Posted by Iwan Eising on září 02, 2005 at 07:23 dop. CEST #
Thanks for the great tips. Here's a suggestion I haven't seen anywhere yet, it's regarding getters and setters: How about 'boxing' the Object-versions of the primitive types in getters and setters?
I quite often need to use these object primitves, and most commonly Boolean, because I need to work with objects rather than primitives, but it is so handy to treat them like primitives, so I create getters and setters that work with the primitives as well. For Boolean objects I create not only the getMyBoolean, but also the isMyBoolean which returns a <u>b</u>oolean. Thanks, Iwan
Posted by Iwan Eising on září 02, 2005 at 07:28 dop. CEST #
Hi Roumen,
Any chance of generating PropertyChange support for the setters as well?
Posted by Anonymous Person on říjen 25, 2007 at 09:27 odp. CEST #