title: java.lang.Integer cannot be cast to java.lang.Long in Kotlin (when the initial value is null)
body: <p>If I have the following, it works (i.e. number get assign 1000)</p>
  
  <pre><code>fun main(args: Array&lt;String&gt;) {
      var number: Long ? = null // or number = 0
      val simpleObject = SimpleClass()
      number = 1000
      println("Hi + $number")
  }
  </code></pre>
  
  <p>If I have the following, it works (i.e. number get assign 1000)</p>
  
  <pre><code>import java.util.*
  
  fun main(args: Array&lt;String&gt;) {
      var number: Long = 0
      val simpleObject = SimpleClass()
      number = simpleObject.getValue&lt;Long&gt;()
      println("Hi + $number")
  }
  
  class SimpleClass() {
      fun &lt;T&gt;getValue(): T {
          return 1000 as T
      }
  }
  </code></pre>
  
  <p>But if I have the below, it fails</p>
  
  <pre><code>import java.util.*
  
  fun main(args: Array&lt;String&gt;) {
      var number: Long? = null
      val simpleObject = SimpleClass()
      number = simpleObject.getValue&lt;Long&gt;()
      println("Hi + $number")
  }
  
  class SimpleClass() {
      fun &lt;T&gt;getValue(): T {
          return 1000 as T
      }
  }
  </code></pre>
  
  <p>The error reported is on the <code>number = simpleObject.getValue&lt;Long&gt;()</code> line</p>
  
  <pre><code>Exception in thread "main" java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.Long 
  </code></pre>
  
  <p>Why when I initialise <code>var number: Long ? = null</code> and <code>var number: Long = 0</code> have different result? Did I get anything wrong?</p>
  
  <p><strong>UPDATED</strong></p>
  
  <p>A workaround using the below, the result is okay. But an additional temp variable is used.</p>
  
  <pre><code>import java.util.*
  
  fun main(args: Array&lt;String&gt;) {
      var number: Long? = null
      val simpleObject = SimpleClass()
      val temp = simpleObject.getValue&lt;Long&gt;()
      number = temp
      println("Hi + $number")
  }
  
  class SimpleClass() {
      fun &lt;T&gt;getValue(): T {
          return 1000 as T
      }
  }
  </code></pre>