由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Java版 - 超级菜鸟问题:什末时候load class
相关主题
Eclipse 编译求助这个怎么不对?
what is your opinion in this case?Where I can find comparison of JVMs
structure in Java??问题征解
菜鸟问题一问请教一个动态cast的问题
请问在Java中有没有停止一切的命令求助,using enum in eclipse
入门Java CLASSPATH问题:Re: Question: Java Synchronization
Re: Help!: tomcat classloading problembasic java question
How to: Abort DOM/XML loading when memory is lowant junit and log4j can't work together
相关话题的讨论汇总
话题: classa话题: myclass话题: line话题: jvm话题: classpath
进入Java版参与讨论
1 (共1页)
c*i
发帖数: 749
1
运行到哪一步装载class?
ClassA MyClass;
MyClass = new ClassA();
c*****t
发帖数: 1879
2

this statement only tells the compiler to reserve a variable space.
^^^^^^^^^^^^^^^^^^^^^^^
here.

【在 c*i 的大作中提到】
: 运行到哪一步装载class?
: ClassA MyClass;
: MyClass = new ClassA();

xt
发帖数: 17532
3

I believe at run time, ClassA is loaded at this line.

【在 c*****t 的大作中提到】
:
: this statement only tells the compiler to reserve a variable space.
: ^^^^^^^^^^^^^^^^^^^^^^^
: here.

m******t
发帖数: 2416
4

I think so, too, because there is an implicit null assignment.
I wouldn't be surprised, though, if some VM chooses to optimizes by waiting
until next line, after all, it doesn't really _have to_ load ClassA on this
line.
It's actually fairly easy to find out, just take ClassA off the classpath, and
look at the exception stack trace. 8-)

【在 xt 的大作中提到】
:
: I believe at run time, ClassA is loaded at this line.

g*******e
发帖数: 14
5

why? JVM does not require classA information for this line.

【在 m******t 的大作中提到】
:
: I think so, too, because there is an implicit null assignment.
: I wouldn't be surprised, though, if some VM chooses to optimizes by waiting
: until next line, after all, it doesn't really _have to_ load ClassA on this
: line.
: It's actually fairly easy to find out, just take ClassA off the classpath, and
: look at the exception stack trace. 8-)

g*******e
发帖数: 14
6

I just try it. exception occurs in the next line.

【在 g*******e 的大作中提到】
:
: why? JVM does not require classA information for this line.

c*****s
发帖数: 214
7
非也。
可以做个小试验。在Class.forName里设个断点
ClassA myClass = null;
System.out.println(ClassA.class);
你会发现ClassA在第二行被加载。
另一个方法是在ClassA里加个static块,看看什么时候执行。

【在 xt 的大作中提到】
:
: I believe at run time, ClassA is loaded at this line.

c*****t
发帖数: 1879
8
hehe, if you have done assembly for Java you won't say this :)

【在 xt 的大作中提到】
:
: I believe at run time, ClassA is loaded at this line.

w******n
发帖数: 692
9
JVM spec doesn't require the lazy loading, though most JVM
works like this way.

【在 c*****t 的大作中提到】
: hehe, if you have done assembly for Java you won't say this :)
m******t
发帖数: 2416
10

waiting
this
classpath, and
Thanks, that's interesting to know.

【在 g*******e 的大作中提到】
:
: I just try it. exception occurs in the next line.

1 (共1页)
进入Java版参与讨论
相关主题
ant junit and log4j can't work together请问在Java中有没有停止一切的命令
库里有一个函数名也叫Time入门Java CLASSPATH问题:
怎么返回空指针呢? Re: Help!: tomcat classloading problem
How to write a file to the same directory of the class file?How to: Abort DOM/XML loading when memory is low
Eclipse 编译求助这个怎么不对?
what is your opinion in this case?Where I can find comparison of JVMs
structure in Java??问题征解
菜鸟问题一问请教一个动态cast的问题
相关话题的讨论汇总
话题: classa话题: myclass话题: line话题: jvm话题: classpath