Tricky compiler behavior
Posted
by Neeraj
on Stack Overflow
See other posts from Stack Overflow
or by Neeraj
Published on 2010-03-23T09:19:58Z
Indexed on
2010/03/23
9:23 UTC
Read the original article
Hit count: 454
Simple java code snippet. It has three classes. After compiling the code please delete A.class and then execute the code. Code still runs, why its not checking whether the byte code of A exists or not?
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();
}
}
}
© Stack Overflow or respective owner