[android-developers] Re: Custom ClassLoader - Urgent!
On Jan 21, 6:31 am, Karl Pauls <karlpa...@gmail.com> wrote:
> > Since the 'test' TestClass instance is created with reference to the
> > new class-loader, I'd expect that after this line executes,
> > test.getClass().getClassLoader() will return an instance of
> > CustomClassLoader, but I always get the default PathClassLoader
> > returned.
>
> Why would you expect that? Java uses parent delegation first so it
> will find the class in the parent and return that one -- hence, its
> classloader is the parent.
It uses parent delegation *by default*. You can override it. (See
e.g. dalvik/tests/068-classloader/src/FancyLoader.java for an
example.)
However, if you do, your custom loader has to take responsibility for
actually loading the class. This can get messy in a hurry.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home