title: Java - comma operator outside for loop declaration
body: <p>I know I can use the comma operator like this</p>
  
  <pre><code>for (int i = 1, j = 15; j&gt;10; i++, j--) {
      // do something neat
  }
  </code></pre>
  
  <p>but some articles seem to suggest that the comma operator can be used outside of the for loop declaration, for example</p>
  
  <pre><code>int j = 2, k = 4 ;
  int x ;
  // Assignment statement with comma operator
  x = j + 1, k ;
  </code></pre>
  
  <p>source: <a href="http://www.cs.umd.edu/~clin/MoreJava/ControlFlow/comma.html" rel="nofollow noreferrer">http://www.cs.umd.edu/~clin/MoreJava/ControlFlow/comma.html</a></p>
  
  <p>or</p>
  
  <pre><code>int x = (expression) ? (i++,2) : 3;
  </code></pre>
  
  <p>source: <a href="https://stackoverflow.com/a/12047433/1084813">https://stackoverflow.com/a/12047433/1084813</a></p>
  
  <p>This would be a neat trick for a code obfuscation contest or to confuse my colleagues, but neither of the examples will compile (Java 1.6, Eclipse Juno), the error is "The left-hand side of an assignment must be a variable". I tried looking at the compiler settings to see whether it could be forbidden to prevent bad code, but without luck.</p>
  
  <p>What's wrong? Was the comma operator a part of an older specification which later changed? Are the people that wrote those examples using a different Java setup that allows this?</p>