title: Promotion of primitive types
body: <p>I have a question about the promotion of primitive types in Java. As we can see in the following example, one of the methods does not compile due to an error of type mismatch. Each method returns the same value but in different types.</p>
  
  <p>The version of primitive <code>long</code> method works without error while the version of wrapper class <code>Long</code> fails. This is because the <code>int</code> literal in the <code>return</code> statement will be first promoted to a broader primitive type (e.g. <code>long</code>) and then to the corresponding wrapper class <code>Integer</code> and so on. Since <code>Integer</code> is not a subclass of <code>Long</code> the compiler gives an error.</p>
  
  <p>But why does the version of wrapper class <code>Byte</code> works without any error? What exactly does the compiler do at this point?</p>
  
  <pre><code>long getPrimitiveLong() {
      return 12; // valid
  }
  
  Long getWrapperLong() {
      return 12; // Error: type mismatch
  }
  
  Byte getWrapperByte() {
      return 12; // valid
  }
  </code></pre>