title: Kotin Type mismatch: inferred type is Int? but Int was expected
body: <p>I am trying to get the Maximum number between two numbers in Kotlin &amp; I keep getting Type mismatch error. I tried using Int?.toInt() It didn't work.</p>
  
  <p>I also tried to use Int!! as the double exclamation for None Null values, It didn't work too.</p>
  
  <pre><code>fun main(args: Array&lt;String&gt;){
  
      val nums = arrayOf(8, 5, 6, 8, 9)
      var sorted = arrayOfNulls&lt;Int&gt;(nums.size)
  
      // manually set 2 values
      sorted[0] = nums[0]
      sorted[1] = nums[1]
  
      for(i in 1 until nums.size-1){
          val value = sorted[i - 1]
          val max = maxOf(value!!, nums[i]) // This line throws Null pointer exception: error: type mismatch: inferred type is Int? but Int was expected
          // do something with max
      }
  
      println(sorted)
  }
  </code></pre>