When does Class#getClassLoader return null?

2019-03-01 08:23发布

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条回答
Summer. ? 凉城
2楼-- · 2019-03-01 08:59

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.

查看更多
登录 后发表回答