3 ms·
This is true, until you're writing a library that's pulled from a repository and used in several projects. If you can't guarantee you're not going to break som
by t-writescode 5y ago
This is true, until you're writing a library that's pulled from a repository and used in several projects.
If you can't guarantee you're not going to break someone else's code by changing:
foo.x to foo.getX();
then you should stick with properties. Now, for staying inside a single package, or a single compiled unit, then what you say is reasonable enough. I'd still prefer to write the getters and setters, though, especially in cases where it's free, like Kotlin.
- commandlinefan 5y agoIt would be better if the default were to not write setters or getters for any properties by default, but instead to write a logical interface that properly encapsulates the properties. Unfortunately, that ship sailed a long time ago for Java.