I’ve been trying to learn more about access modifiers in java, and everyone has said “Use private to hide things that you don’t want other classes / methods using” and I’m just left wondering why that needs to be done. I can’t think of a single case where private would make sense to use as a sole developer…
That issue extends to not mentioning an access specifier too. It seems like it’s just limiting the flow of information, since the user has no way of seeing the code that we’re generating…
Any help on understanding this better would be greatly appreciated since I tend to learn better from programming anyways. Thanks a ton!
Even as a sole developer you can make mistakes, think of code you touch/use months after writing it.
Using correct access modifiers helps with encapsulation, structuring code and avoiding mistakes (like accidently changing some class’ internal state).
I can’t quite follow you here but you always mention an access modifier, not writing one just means default (package private) access. Also note that users of your code (in case of libraries etc.) will see all members and their access modifiers and they might try and access some fields that should not be modified directy if access to those fields wasn’t restricted.