Direct access is good. However, no one can say that access to getter / setter is bad, inside the same class. If you are developing a Java bean, you will definitely understand what I'm saying. Think you're trying to get JTextField user input as a string. In this case, the getter methods will allow you to do many things, including truncating strings, trimming, uppercase letters, lowercase letters, etc. If you are trying to do this all by simply accessing a direct variable (for example: String s = textField.getText ()), it will be difficult for you to do this. So, what I think is good or bad depends on the situation and what you are developing.
source share