What is the difference between Class.getResource() and ClassLoader.getResource()?

前端 未结 7 1887
情歌与酒
情歌与酒 2020-11-22 02:25

I wonder what the difference is between Class.getResource() and ClassLoader.getResource()?

edit: I especially want to know if any cachi

7条回答
  •  后悔当初
    2020-11-22 03:20

    Had to look it up in the specs:

    • Class.getResource(String resource)

    • ClassLoader.getResource(String resource)

    Class's getResource() - documentation states the difference:

    This method delegates the call to its class loader, after making these changes to the resource name: if the resource name starts with "/", it is unchanged; otherwise, the package name is prepended to the resource name after converting "." to "/". If this object was loaded by the bootstrap loader, the call is delegated to ClassLoader.getSystemResource.

提交回复
热议问题