I have a situation where I have to load a named class. If there are several classes with the same name in my class (e.g. com.example.myclass), I should load both. I use the loadClass () method of my CustomLoader class, which comes from java.lang.ClassLoader. I have not changed the behavior of the parent class, but just call the parent methods. My problem is that if there are two classes with the same name, I can only load one of them. I looked at the web solution but could not find it. I found many solutions for reloading classes by creating a new instance of the class loader, but in my case, the new instance will probably load the first class again. Can this problem be solved?
EDIT: I forgot to mention that two classes with the same name are in different jar files.
EDIT: Both John and Stephen gave the same solution, but I can only mention one answer. Sorry :( I even voted for both answers.
source
share