Reputation: 19589
A ClassLoader should delegate the loading process to it's parent first. This is some docs says.
So, what happen if we don't follow this pattern. that is:
We override loadClass, and in it's implementation, we directly call:
defineClass(...) // get Class objet for a given byte array
resoveClass(...) // link class to vm
Upvotes: 1
Views: 626
Reputation: 6548
Tomcat's Web Application Classloader is an example of a Classloader that does not (always) delegate the loading process to its parent first (as per Servlet Specification). The classloader-howto article explains this and also gives insight in what (not) to do. If you want to know how it works in practice, you can view the source code of WebappClassLoader.
On a side node, creating a URLClassLoader without passing on Thread.currentThread().getContextClassLoader()
as parent classloader in the constructor can give surprising results if the current Thread was started with a custom Classloader. The URLClassLoader will only know the classes from the System Classloader and the classes in the URLs provided, but not the classes from the custom Classloader.
Upvotes: 2