New answers tagged

0

Whether or not you should access a field directly by the dot operator or through a getter method depends on what you are doing. In general, the code that you write should not expose it's interior fields to outside callers without a very good reason. "Because I want to type less" doesn't qualify. So, most of the time you will use a getter method when ...


3

This boils down to the coding standard in use. Typically what I've seen in Java is that all member variables are declared private and mutators/accessors (setters/getters) are provided on an as-needed basis. If the code in question is developed by a third party, and allows both object.someVariable and object.getSomeVariable() then my gut instinct is that ...



Top 50 recent answers are included