Answer the question
In order to leave comments, you need to log in
What is the correct way to use class fields inside a class?
Question for Java programmers who work in companies where code reviews are carried out.
What is the correct way to use class fields inside the class: directly or through setters/getters?
For example:
Inside the class human there is a private field age that I want to use inside a method of the class human.
What is more correct:
if (age == 18) goArmy();
or
if (getAge() == 18) goArmy();
And the same question in the case of assignment: directly or through a setter?
Answer the question
In order to leave comments, you need to log in
on the getAge() and other methods, you can always hang breakpoints and see in the debugger who, for example, rewrites the value.
For this reason, in our team, for example, we abandoned the simple state
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question