Does "if" always wait method to finish?
<p>I'm fairly new to Java and have a doubt that needs to be cleared.</p>

<p>Using code like this:</p>

<pre><code>public int x;

public int elaborateX(){
    x = 0;
    setX();
    x+=1;
    return x;
}

public void setX(){
    //...
    //some workload here
    //...
    x = 5;
}
</code></pre>

<p>As I understand there are chances (especially if the method setX() does more than just set x ) that elaborateX() will return "1".</p>

<p>I know after looking the issue around that Threads can be used to prevent the "bug", but my question is; will the following always wait for setX() to be finish executing?</p>

<pre><code>public int x;

public int elaborateX(){
    x = 0;
    if(setX()){
       x+=1;
    };

    return x;
}

public boolean setX(){
    //...
    //some workload here
    //...
    x = 5;
    return true;
}
</code></pre>

<p>Will elaborateX() always return "6" in this case?</p>

<p>I'm asking because I need to be 100% sure otherwise I will use the "proper approach" instead of this "trick".</p>

<p>Thanks</p>
