これは非常に単純なコードです。
package test;
public class Test {
public static void main(String[] args) {
System.out.println("test");
}
}
私はそれを実行します:java -verbose:class Test、そして以下は出力です。なぜこれほど多くのクラスがロードされるのですか?Javaは必要に応じてクラスをロードしませんか?
[Opened C:\Program Files\Java\jdk1.7.0_11\jre\lib\rt.jar]
[Loaded java.lang.Object from C:\Program Files\Java\jdk1.7.0_11\jre\lib\rt.jar]
[Loaded java.io.Serializable from C:\Program Files\Java\jdk1.7.0_11\jre\lib\rt.jar]
[Loaded java.lang.Comparable from C:\Program Files\Java\jdk1.7.0_11\jre\lib\rt.jar]
[Loaded java.lang.CharSequence from C:\Program Files\Java\jdk1.7.0_11\jre\lib\rt.jar]
[Loaded java.lang.String from C:\Program Files\Java\jdk1.7.0_11\jre\lib\rt.jar]
[Loaded java.lang.reflect.GenericDeclaration from C:\Program Files\Java\jdk1.7.0_11\jre\lib\rt.jar]
[Loaded java.lang.reflect.Type from C:\Program Files\Java\jdk1.7.0_11\jre\lib\rt.jar]
[Loaded java.lang.reflect.AnnotatedElement from C:\Program Files\Java\jdk1.7.0_11\jre\lib\rt.jar]
[Loaded java.lang.Class from C:\Program Files\Java\jdk1.7.0_11\jre\lib\rt.jar]
[Loaded java.lang.Cloneable from C:\Program Files\Java\jdk1.7.0_11\jre\lib\rt.jar]
[Loaded java.lang.ClassLoader from C:\Program Files\Java\jdk1.7.0_11\jre\lib\rt.jar]
[Loaded java.lang.System from C:\Program Files\Java\jdk1.7.0_11\jre\lib\rt.jar]
[Loaded java.lang.Throwable from C:\Program Files\Java\jdk1.7.0_11\jre\lib\rt.jar]
[Loaded java.lang.Error from C:\Program Files\Java\jdk1.7.0_11\jre\lib\rt.jar]
...
test
[Loaded java.lang.Shutdown from C:\Program Files\Java\jdk1.7.0_11\jre\lib\rt.jar]
[Loaded java.lang.Shutdown$Lock from C:\Program Files\Java\jdk1.7.0_11\jre\lib\rt.jar]