Class.getResource and ClassLoader.getSystemResource: is there a reason to prefer one to another?

后端 未结 4 2099
借酒劲吻你
借酒劲吻你 2020-12-04 16:40

I saw both Class.getResource and ClassLoader.getSystemResource used to locate a resource in Java. Is there any reason to prefer one to another?

4条回答
  •  醉话见心
    2020-12-04 17:14

    ClassLoader.getSystemResource() will use the bootstrap (system) classloader.

    Class.getResource() will use that particular instance of Class's classloader, in other words whatever classloader was used to load that class. This may be a different classloader than the system classloader.

提交回复
热议问题