0

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?

stdout
  • 2,471
  • 2
  • 31
  • 40
  • Simple understanding, you have MyClass code in your program in java, you use an external package that somehow(or more likely made to have) a class with the same name MyClass name inside it. That class will have access to all data inside your MyClass even if its private – David Coler Oct 17 '18 at 15:11
  • I don't quite understand what you're saying but what I'm asking has nothing to do with having two classes with the same name. I'm asking if it's possible to EXTERNALLY define a class within the same package of a library module (lets say a jar file) which I already use in my code and thus be able to access package-private data of that library module. – stdout Oct 18 '18 at 07:47

0 Answers0