这种问题有P的好讨论的
自己试试不就知道了? 这点学习能力都没 ?public class A
{
public static void main(String[] arg) throws InterruptedException
{
System.err.println("start \t" + System.currentTimeMillis());
Thread.sleep(5000);
B objB = new B();
C objC;
} } class B
{
static
{
System.err.println("load B \t" + System.currentTimeMillis());
}
} class C
{
static
{
System.err.println("load C \t" + System.currentTimeMillis());
}
}
自己试试不就知道了? 这点学习能力都没 ?public class A
{
public static void main(String[] arg) throws InterruptedException
{
System.err.println("start \t" + System.currentTimeMillis());
Thread.sleep(5000);
B objB = new B();
C objC;
} } class B
{
static
{
System.err.println("load B \t" + System.currentTimeMillis());
}
} class C
{
static
{
System.err.println("load C \t" + System.currentTimeMillis());
}
}
你发表的看法是关于“申明一个类对象时是否加载Class”的问题。
类在申明的时候,没有被实例化(没有被真正用到)的时候是不会加载的。这个大家都知道。我想问的是:
jvm加载Class是否真的有我上面说的第二种情况这么种机制。如果有的话,那么Class被加载的时机就不能按照
“真正用到”这个来判断了。