I am trying to debug a very strange class error by looking at the ClassLoader
s for some dynamically created components. ClassLoader
s are something I've never played much with - and im surprised that standard JDK classes have null Class loader instances.
Can somebody explain the output of this simple main method in terms of the classes whose loaders I am attempting to print, and also more generally:
- the way
ClassLoader
s work on the JVM and
- how we can debug missing classes using
ClassLoader
s.
public class MyClass {
/**
* @param args
*/
public static void main(String[] args) {
System.out.println(relfect.MyClass.class.getClassLoader());
System.out.println(String.class.getClassLoader());
System.out.println(ArrayList.class.getClassLoader());
System.out.println(JButton.class.getClassLoader());
System.out.println(System.class.getClassLoader());
Boolean b = new Boolean(true);
System.out.println(b.getClass().getClassLoader());
}
}
Output
sun.misc.Launcher$AppClassLoader@1f7182c1
null
null
null
null
null
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…