Answer the question
In order to leave comments, you need to log in
Answer the question
In order to leave comments, you need to log in
This is called a growth point, you leave the method so that you can then add something to it.
For example, updating some construction after assigning a number more than 10 to a variable, what will you do if the variable is public? Rewrite all the code where it was used?
Setters often do value checks and validations; in the case of getters, they can combine the values of multiple fields. The logic changes in one place, not many.
Java libraries, such as serialization, and therefore frameworks based on them, use getters and setters
I highly recommend Joshua Bloch - Effective Java 2nd Edition, Item 14.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question