Can a compiler assign a value to a variable before the variable is actually triggered?

I just read http://www.javaworld.com/javaworld/jw-04-2003/jw-0425-designpatterns.html?page=5 and it says:

the compiler can assign a value to a singleton variable before a single constructor is called

I am wondering if this is a typo. Do they really mean to say: the JVM implementation is free instead , the compiler is free .

and my second question is that we have this problem with C # / VB? (in which the "compiler" "is free to assign a value to a variable before the variable is fully run / even before the constructor function of the variable class is fully run.

+3
source share
2 answers

The answer to the first part of the question is that you are right, although this is more likely a case of careless terminology than a typo or mistake. (Obviously, the compiler does not assign values ​​to variables ... this only happens when the code generated by the compiler is executed.)

A more technically accurate repetition would be:

"... , , - , singleton, ."

, , , () . Java , , . (- , , .)

( , - -, , , . - . , , JIT.)


# VB , .

+1

Java - . , -

Object o = new Object();

:

0:  new #2; //class java/lang/Object
3:  dup
4:  invokespecial   #1; //Method java/lang/Object."<init>":()V
7:  astore_1

0 , . 4. , , , . .

- CLR, , JVM, , . , , .

+4

All Articles