Another subtlety is that getClassLoader() may return null, if the
class was loaded by the primeval ClassLoader().
The Class method getResource() knows this and acts accordingly:
- - - -
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);
}
- - -
Also, Class.getClassLoader() may be restricted by security policies,
while Class.getResource() is not (its code pasted above).
For details, see the source for Class.getClassLoader().
In general, I'd use the following, unless there's a good reason not
to and you're taking a null ClassLoader possibility into account.
rslt = this.getClass().getResource(name);
-- GG
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Java-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/java-dev/email@hidden