シンプルな Java コード スニペット。3つのクラスがあります。コードをコンパイルしたら、A.class を削除してからコードを実行してください。コードはまだ実行されますが、A のバイト コードが存在するかどうかを確認しないのはなぜですか?
class A {
static {
System.out.println("In the class A");
}
public A() {
}
}
class B {
private A a = null;
static {
System.out.println("In the class B");
}
public B() {
a = new A();
}
}
public class ExampleLinkage {
static {
System.out.println("In the class A");
}
public ExampleLinkage(String str) {
}
public static void main(String args[]) {
try {
System.out.println("In the main method of ExampleLinkage");
Class.forName("com.bt.rtti.B");
} catch(Exception e) {
e.printStackTrace();
}
}
}