I know the benefits of using getters/setters for any attributes in Java when accesing them from outside the class, but do these best practices include internal accesses?
It is common to see constructor methods setting variables by this.foo = foo, like this:
public class Person {
private int age;
private String firstName;
private String lastName;
public Person(String firstName, String lastName, int age) {
this.age = age;
this.firstName = firstName;
this.lastName = lastName;
}
// getters & setters...
What should I do if I need to access an attribute from inside the class?
Thank you in advance.
EDIT: Thank you for all your comments. It seems to be a matter of opinion, providing that there seems not to be a 'best practice' for this case.