Class#getClassLoader何时返回null? [英] When does Class#getClassLoader return null?

查看:71
本文介绍了Class#getClassLoader何时返回null?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说我有一些Java代码:

Say I have some Java code:

public class Widget {
    ...whatever
}

还有一些代码可以加载小部件

And some code that classloads the Widget:

ClassLoader widgetLoader = Widget.class.getClassLoader();

可以 widgetLoader 曾经?为什么/为什么不呢?如果是这样,在什么情况下?

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

推荐答案

根据这种方法javadoc


返回类的类加载器。某些实现可能使用
null来表示引导类加载器。如果此类由引导程序
类加载器加载,则此方法将在此类实现中返回
null。

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.

这篇关于Class#getClassLoader何时返回null?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆