This is the mail archive of the
kawa@sources.redhat.com
mailing list for the Kawa project.
Re: about ClassLoaders
- To: Chris <chris at tech dot com dot au>
- Subject: Re: about ClassLoaders
- From: Ivan Toshkov <toshkov at crosswinds dot net>
- Date: 11 Apr 2001 14:59:30 +0300
- Cc: kawa at sourceware dot cygnus dot com
On 11 Apr 2001 18:58:42 +1000, Chris wrote:
> I notice that if you try and redefine a class with a ClassLoader, Java
> throws an error, but if you
> create a new ClassLoader, Java will let the new ClassLoader recreate
> the Class. Has anybody
> got any insights about why this should be so?
I coundn't understand how exactly do you "redifne" the class. Perhaps
some code snippet will clarify the problem.
>
> Also, I see that if you declare a Foo class in your code, and then
> manually load a Foo class with
> a custom ClassLoader, Java won't recognise them as being the same
> class. Assuming that no
> Foo class has previously been loaded before you manually load one, I
> wonder why Java makes
> the assumption that they are different classes. It kind of creates an
> inpenetratable wall between
> classes loaded by the bootstrap ClassLoader and any custom ClassLoader.
> Well, not quite
> inpenetratable, but semi. Has anybody got any insights about these murky
> matters? The java doco
> is pretty vague about these issues. Is this something fundamental about
> the Java security design
> perhaps?
>
Each class loader (except one) has a "parent" class loader. The
procedure for loading a class is:
1) check if the class loader has already loaded the class
2) check if the parent class loader has already loaded the class
3) if so, return the already loaded class
4) try to load the class.
Each class has a reference to the class loader which loaded it, and if a
method of that class cites some class, it is checked starting with the
methods class loader.
So if you have a scheme of class loaders like this:
A
|---B
|---C
And you have loaded class X, using class loader B, class loader C
doesn't know anything about it and will try to load a new instance
(which can be a completely different class, for that matter).
--
Ivan Toshkov