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

前端 未结 7 1948
情歌与酒
情歌与酒 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:22

    The first call searches relative to the .class file while the latter searches relative to the classpath root.

    To debug issues like that, I print the URL:

    System.out.println( getClass().getResource(getClass().getSimpleName() + ".class") );
    

提交回复
热议问题