A
Andrew Thompson
As far as I understand, this code should print the URL
to the source, twice.
<sscce>
import java.net.URL;
public class WhereAmI {
static String name = "WhereAmI.java";
public WhereAmI() {
System.out.println( getURL(this, name) );
}
public static URL getURL(Object o, String address) {
return o.getClass().getResource(address);
}
public static void main(String[] args) {
Object o = new Object();
System.out.println( getURL(o, name) );
WhereAmI wai = new WhereAmI();
}
}
</sscce>
However, the output I am getting is ..
null
file:/D:/projects/.../WhereAmI.java
Why does the first invocation of getResource(), from main()
using a generic 'Object' fail? As I understand the JavaDocs,
either form should work.
Andrew T.
to the source, twice.
<sscce>
import java.net.URL;
public class WhereAmI {
static String name = "WhereAmI.java";
public WhereAmI() {
System.out.println( getURL(this, name) );
}
public static URL getURL(Object o, String address) {
return o.getClass().getResource(address);
}
public static void main(String[] args) {
Object o = new Object();
System.out.println( getURL(o, name) );
WhereAmI wai = new WhereAmI();
}
}
</sscce>
However, the output I am getting is ..
null
file:/D:/projects/.../WhereAmI.java
Why does the first invocation of getResource(), from main()
using a generic 'Object' fail? As I understand the JavaDocs,
either form should work.
Andrew T.