简体   繁体   English

this.getClass()。getClassLoader()和ClassLoader

[英]this.getClass().getClassLoader() and ClassLoader

What's the difference between this.getClass().getClassLoader().getResource() and ClassLoader#getResource() ? this.getClass()。getClassLoader()。getResource()和ClassLoader#getResource()有什么区别?

Frank 坦率

The first is the actual code, the second is just a pointer which class/method you should use. 第一个是实际的代码,第二个只是您应该使用的类/方法的指针

By the way, you should rather have asked this minor question/request-for-clarification in a comment on my answer in your previous question . 顺便说一句,您宁可在对上一个问题的回答中评论这个较小的问题/要求澄清。

You mean difference between " Class #getResource()" and " ClassLoader #getResource()"? 您是说“ Class #getResource()”和“ ClassLoader #getResource()”之间的区别吗? If you look at JVM srcs (recommended), you will see that the first is a convenience wrapper method around the latter: 如果查看JVM srcs(推荐),您会看到第一个是围绕后者的便捷包装器方法:

public java.net.URL getResource(String name) {
    name = resolveName(name);
    ClassLoader cl = getClassLoader0();
    if (cl==null) {
        // A system class.
        return ClassLoader.getSystemResource(name);
    }
    return cl.getResource(name);
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 this.getClass()。getClassLoader()。getResource()==异常 - this.getClass().getClassLoader().getResource() == Exception this.getClass()。getClassLoader()。getResourceAsStream()在RCP产品中不起作用 - this.getClass().getClassLoader().getResourceAsStream()is not working in RCP product this.getClass()。getClassLoader()。getResourceAsStream始终返回null - this.getClass().getClassLoader().getResourceAsStream always returning null 等价于Jar中的this.getClass()。getClassLoader()。getResource(“。”)。toURI() - Equivalent of this.getClass().getClassLoader().getResource(“.”).toURI() from within a Jar ClassLoader.getSystemClassLoader()vs obj.getClass()。getClassLoader()。getSystemClassLoader() - ClassLoader.getSystemClassLoader() vs obj.getClass().getClassLoader().getSystemClassLoader() getClass().getClassLoader() 是null,为什么? - getClass().getClassLoader() is null, why? “ this.getClass()。getSuperclass()”的意外输出 - Unexpected output of “this.getClass().getSuperclass()” 为什么在Java中这是可能的:this.getClass()。getClass()。getClass()...等 - Why is this possible in Java: this.getClass().getClass().getClass()…etc getClass()。getClassLoader()。getResourceAsStream()正在缓存资源 - getClass().getClassLoader().getResourceAsStream() is caching the resource getClass()。getClassLoader()。getResourceAsStream引发NullPointerException - getClass().getClassLoader().getResourceAsStream is throwing a NullPointerException
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM