0

What's the difference between this.getClass().getClassLoader().getResource() and ClassLoader#getResource() ?

Frank

Jim Counts
  • 12,535
  • 9
  • 45
  • 63
Frank
  • 30,590
  • 58
  • 161
  • 244

2 Answers2

2

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.

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
1

You mean difference between "Class#getResource()" and "ClassLoader#getResource()"? If you look at JVM srcs (recommended), you will see that the first is a convenience wrapper method around the latter:

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);
}
adaf
  • 258
  • 1
  • 8