Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Not being an expert on the Java VM, I'll still try to answer your question:</p> <ol> <li><p>Your problem is actually not one that concerns the compiler - the compiler only turns your readable Java code into binary instructions. The problem of having uninitialized variables would occur at runtime, unless the compiler was "smart" enough to find circular dependencies in your code.</p></li> <li><p>None of your values are constants - they would have to be declared <code>final</code>, and you would not be able to set <code>anotherConstant</code> like that if you had it declared that way. They are both variables.</p></li> <li><p>At first, your class will be loaded into memory. So the basic memory layout of <code>SomeClass</code> will be known, and so will the functionality of <code>someMethod()</code>. If you had static variables declared, they would also be initialized now, but you couldn't call an instance method like <code>someMethod</code> to do so.</p></li> <li><p>When you instantiate an object of type <code>SomeClass</code>, all the member variables will be set first, so <code>someConstant</code> will no longer be unknown. Since the functionality of <code>someMethod</code> is also known, this should not be a problem. Were you referring to an undeclared variable at some point in <code>someMethod</code>, a <code>NullPointerException</code> would be thrown.</p></li> <li><p>Finally, the constructor is called. At this point, all the member variables are available, so it all will run smoothly. Again - were there any undeclared variables, a <code>NullPointerException</code> would be thrown. In your example, there should not be any, though.</p></li> </ol>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload