Multiple instances of static variables

前端 未结 4 1308
自闭症患者
自闭症患者 2021-02-13 14:42

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,

4条回答
  •  一向
    一向 (楼主)
    2021-02-13 15:48

    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.

提交回复
热议问题