Java: set value and check condition at same time
<p>(In the process of writing my original question, I answered it, but the information might be useful to others, and I thought of a new question)</p>

<p>For instance:</p>

<pre><code>int x;
if (x = 5) { ... }
</code></pre>

<p>Creates an error:<br>
    Type mismatch: cannot convert from int to boolean. (Because assignment doesn't return a<br>
    boolean value)</p>

<p>However,</p>

<pre><code>int x; 
if ((x = 5) == 5) { 
    System.out.println("hi!");
}
</code></pre>

<p>will print out "hi!"</p>

<p>And similarly,</p>

<pre><code>String myString = "";
if ((myString = "cheese").equals("cheese")) {
    System.out.println(myString);
}
</code></pre>

<p>prints out "cheese"</p>

<p>Sadly,</p>

<pre><code>if ((int x = 5) &gt; 2) { ... }
</code></pre>

<p>does not work with an in-line declaration.  How come?  Can I get around this?</p>
