title: Code Object o = true ? new Integer(0) : new Long(1) returns Long with value 0. Why?
body: <p>Please consider we have code below:        </p>
  
  <pre><code>Object obj = true ? new Integer(0) : new Long(1);
  System.out.println(obj.getClass() + "\nvalue = " + obj);
  </code></pre>
  
  <p>And its result is:</p>
  
  <pre><code>class java.lang.Long
  value = 0
  </code></pre>
  
  <p>Instead of:</p>
  
  <pre><code>class java.lang.Integer
  value = 0
  </code></pre>
  
  <p>Could someone clarify why we have such functionality in Java? It is very strange for me.
  Do you have any example where this can be useful?</p>
  
  <p>UPDATE:
  Here is piece of bytecode, where we can see, whats going on there</p>
  
  <pre><code>NEW java/lang/Integer
  DUP
  LDC "0"
  INVOKESPECIAL java/lang/Integer.&lt;init&gt; (Ljava/lang/String;)V
  INVOKEVIRTUAL java/lang/Integer.intValue ()I
  I2L
  INVOKESTATIC java/lang/Long.valueOf (J)Ljava/lang/Long;
  ASTORE 1
  </code></pre>