Does system classloader load all classes in classpath even if they're not actually used?

泄露秘密 提交于 2019-12-02 01:53:20

No, The ClassLoader loads the class when the class is needed in memory. It doesn't load all classes at once as it can run out of memory.

They are loaded when needed. But what "when needed" means, might depend on the classloader. Typically, when a class is loaded it also checks the existence of all classes it references - and it might also load them.

You can check it by adding the option -verbose to your Java JVM, it outputs then all the classes it loads, and from where.

To my knowledge it's impossible to load all classes if they are not accessed explicitly. Class in only loaded when it's constructor or any other static member is first accessed, this rule applies to nested classes as well.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!