Re: is package a namespace?
puzzlecracker wrote:
Is it possible to have the same package extend over different
hierarchical file-system trees --still retain the same structure and
name -- and then place them into the same jar file, and they both can
access each other's package private members?
If you write your own ClassLoader, you can load classes
from any place you like. Note, though, that classes loaded
by different ClassLoaders are in different packages, even if
their package names are nominally identical. That is, if CL1
loads the class foo.bar.Baz and CL2 also loads a foo.bar.Baz,
the two classes are distinct and are in different packages
for the purposes of access rights.
Is it like in C++ that packages can be wired together, thus a
malicious code can be introduce that can tinker with internals of some
api... or Java worked around this problem?
I don't know C++ and can't say whether Java is "like" it,
nor whether Java shares the same problems. If you're worried
that a custom ClassLoader could substitute its own String or
JButton for those provided with Java, the answer is No: You
can load a new java.lang.String or javax.swing.JButton class,
but they won't be the same classes as those Java provides, nor
will they be in the same packages.
--
Eric Sosman
esosman@ieee-dot-org.invalid