title: Why does variable initialization of to an assignment expression [String x = (x = y)] compile?
body: <p>How does this compiles without error?  As my understanding, the compiler checks the type of the variable (in this case <code>String</code>), then sees if the type of the expression on the right side corresponds to the variable's type (or at least a subtype but let's stick to the simple case with the <code>String</code> class since it's final). </p>
  
  <pre><code>public class InitClass {
    public static void main(String[] args) {
      String str = (str = "hello");
      System.out.println(str);
    }
  }
  </code></pre>
  
  <p>My question is how does <code>str = "hello"</code> compile? Is the compiler already aware that <code>str</code> should be of type <code>String</code>?</p>