private access modifier behavior in case of package collision
Let's say, I am using a 3rd party jar A.jar
in my project, with some members (classes, methods etc.) with default access (package private). Now, if I create the same package name in my project, I am able to access the members with default access modifier from A.jar (I tried this with Java Projects in Eclipse).
Oracle's document says:
If a class has no modifier (the default, also known as package-private), it is visible only within its own package
Isn't this philosophy violated in this particular use case(that too without using reflection), given that it is not what the developer of A.jar
would have intended, as she would have wanted only classes in her package to access this particular member?
Also does it mean, that package-private is a convenience mechanism, but can't be used for securing the data etc.?
Isn't this philosophy violated in this particular use case(that too without using reflection), given that it is not what the developer of A.jar would have intended, as she would have wanted only classes in her package to access this particular member?
If she used default access modifier she would have less interested in securing her default members.
链接地址: http://www.djcxy.com/p/24048.html上一篇: 公共javax.swing.Box.Filler从另一个包?
下一篇: 包冲突情况下的私人访问修改器行为