title: Integer arithmetic in Java with char and integer literal
body: <p>Can someone explain to me why the following code compiles OK in Java?  </p>
  
  <pre><code>char c = 'a' + 10;
  </code></pre>
  
  <p>Why is this not equivalent to the following, which does not compile?  </p>
  
  <pre><code>int i = 10;
  char c = 'a' + i;
  </code></pre>
  
  <p>The Java Language Specification (section 3.10.1) states "An integer literal is of type <code>long</code> if it is suffixed with an ASCII letter L or l (ell); otherwise it is of type <code>int</code> (§4.2.1)." Section 4.2.2 refers to "The numerical operators, which result in a value of type <code>int</code> or <code>long</code>." So the result of the addition should, in my understanding, be an <code>int</code>, which cannot be assigned to the <code>char</code> variable <code>c</code>.</p>
  
  <p>However, it compiles fine (at least in Sun JDK 1.6.0 release 17 and in Eclipse Helios).</p>
  
  <p>Rather an artificial example perhaps, but it is used in an introductory Java course I have been teaching, and it now occurs to me that I don't really understand why it works.</p>