Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eclipse generate getters and setters does not encapsulate

When I do quick fix on a field in eclipse I can generate a getter and setter for the field. This also makes the field private und subsequently transforms all access for this field in all source files to use the getter and setter. This is the case for a single field.

However if I do contextmenu > Source > Generate Getters and Setters... (the option to use when you want to affect all fields) it does not make the beforementioned change and all access to the fields in the source code is left as is.

Am I overlooking something?

like image 301
cdbeelala89 Avatar asked Feb 13 '13 15:02

cdbeelala89


People also ask

Do getters and setters provide encapsulation?

Encapsulation in Java – Hiding the variables of a class from other classes, and giving access to them only through methods(setters and getters). Hence, Encapsulation in Java language means binding the data (variables) with the code(methods – setters and getters).

Can Eclipse generate getters and setters?

An Eclipse plugin which generates Javadoc for getters and setters of a Java class. The generated Javadocs are based on those of fields corresponding to the getters or setters.

Do getters break encapsulation?

Having getters and setters does not in itself break encapsulation.


1 Answers

The quick fix is not going to this menu. The menu that the quick fix call is accessible from Context Menu -> Refactor -> Encapsulate Field

like image 182
Daniel Pereira Avatar answered Sep 17 '22 11:09

Daniel Pereira