I have been reading the tutorial Controlling Access to Members of a Class. I am confused what might be good use case for using package-private. Because as I understand, you can always change your package declaration to whatever the package declaration of such a class and act as if that is a public class. I understand that this is not a good thing to do, but what is stopping me?
Share
Well, for one thing, the access modifiers are there to help the developer. There’s always ways around them, such as via reflection for instance.
Not much really!
As a developer you can however distribute your classes in sealed .jar-files which basically means that you’re not letting anyone else in to your packages.
From Sealing Packages within a JAR File