findClass (String) will be called by the loadClass (String) method of the class loader. By default, the implementation throws a ClassNotFoundException and is intended to override class loaders.
The loadClass (String) method will call the following methods in this order
- First he tries to find if the class is already loaded:
findLoadedClass(String) - Then, if it is not found, it calls the method of the parent class_classes
loadClass(String). - If not found, it will call the method
findClass(String)(user load)
Thus, all a custom classloader should do is to override the method findClass(String)for loading classes in its own way. This will ensure proper delegation when loading classes. Check the links (javadoc), explain what steps are being taken and how it is called findClass(String)fromloadClass(String)
, ()
ClassLoader A B ( findClass loadClass)
A.loadClass()
|
(not-found?) (by findLoadedClass)
|
B.loadClass()
|
(not found?) (by findLoadedClass)
|
systemclassloader.loadClass() (Bs parent, also can be
| called classpath classloader)
|
(not found?) (by findLoadedClass)
|
bootstrap classloader.loadClass() (the bootstrap classloader,
| this has no parent)
|
(not found?)
|
systemclassloader.findClass() (on system classloader,
| will try to "find" class in "classpath")
|
(not found?)
|
B.findClass()
|
(not found?)
|
A.findClass()
|
(not found?)
|
ClassNotFoundException
, (eigther by findClass findLoadedClass), .