When does Class#getClassLoader return null?

怎甘沉沦 提交于 2019-12-31 04:43:11

问题


Say I have some Java code:

public class Widget {
    ...whatever
}

And some code that classloads the Widget:

ClassLoader widgetLoader = Widget.class.getClassLoader();

Can widgetLoader ever be null? Why/why not? If so, under what circumstances?


回答1:


According to this method javadoc:

Returns the class loader for the class. Some implementations may use null to represent the bootstrap class loader. This method will return null in such implementations if this class was loaded by the bootstrap class loader.



来源:https://stackoverflow.com/questions/17723303/when-does-classgetclassloader-return-null

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