Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generate getters and setters in NetBeans [closed]

I Need to know how to have NetBeans generate getters and setters using a shortcut.

like image 811
Zvjezdan Avatar asked Jan 12 '14 12:01

Zvjezdan


People also ask

Why are there no getters and setters?

Getter and setter methods (also known as accessors) are dangerous for the same reason that public fields are dangerous: They provide external access to implementation details. What if you need to change the accessed field's type? You also have to change the accessor's return type.

Can we use getters without setters?

Depends on if the value you are talking about is something you want to let other classes modify - in some cases the answer is yes, in some it is no. If the answer is no then there is no reason to add a setter method and in fact it might harm things.

Do getters and setters break encapsulation?

Having getters and setters does not in itself break encapsulation. What does break encapsulation is having a getter and a setter for every data member (every field, in java lingo). That is one step away from making all data members public.


1 Answers

Position the cursor inside the class, then press ALT + Ins and select Getters and Setters from the contextual menu.

like image 83
Stefano Sanfilippo Avatar answered Sep 19 '22 14:09

Stefano Sanfilippo