Adding an external class with the same package name and breaking encapsulation

178 views Asked by At

I've run into this statement when I was reading a book on Kotlin:

With Java, the encapsulation can be easily broken, because external code can define classes in the same packages used by your code and thus get access to your package-private declarations...

I'm not sure if I get this totally correct but does it mean can I somehow define a class in the same package with, for example, a third-party module that I depend on and then access it's package-private data? Or does it mean something else?

0

There are 0 answers