Getters and setters are mandatory for others classes to access instance variables of a class to not violate the encapsulation principle (which is quite important in OO programming). In the end it’s a matter of choice, but you’re saving one method call using your first example.