I\'m experimenting with using different classloaders to load a particular class, and see if the static variables in that class can have different instances.
Basically,
Your problem is that new CustomClassLoader()
creates a classloader that will try to delegate loading classes to the system classloader - and that will be the same for both instances. Your CustomClassLoader
also isn't even able to load classes itself. Try using an URLClassLoader
and passing null
as parent.
As for real world applications: it's essential for Java Web containers and app servers by allowing different apps to be completely isolated from each other even though they may be using many of the same classes.