title: Kotlin NDArray with a lambda constructor with generic return type
body: <p>I'm trying to create a very simple generic NDArray class in Kotlin that takes a lambda expression as an init function.</p>
  
  <pre><code>class NDArray&lt;T&gt;(i: Int, j: Int, f: (Int) -&gt; T) {
      val values: Array&lt;T&gt; =  Array(i * j, f)
  }
  </code></pre>
  
  <p>A typical usage would be:</p>
  
  <pre><code>fun main(args: Array&lt;String&gt;){
      val m = NDArray(4, 4, ::zero)
  }
  
  fun zero(i: Int) =  0.0
  </code></pre>
  
  <p>My problem is that the Kotlin compiler complains on the initialisation of values in the constructor</p>
  
  <pre><code>values = Array(i * j, f)
  </code></pre>
  
  <p>by saying "Cannot use 'T' as reified type parameter. Use class instead". Why ?</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>If I instead replace the Kotlin Array implementation with my own MyArray it compiles:</p>
  
  <pre><code>class NDArray&lt;T&gt;(i: Int, j: Int, f: (Int) -&gt; T) {
      val values: MyArray&lt;T&gt; =  MyArray(i * j, f)
  }
  
  class MyArray&lt;T&gt;(i:Int, init: (Int) -&gt; T) {
      ...
  }
  </code></pre>
  
  <p>Not sure why Kotlin treats MyArray differently from a regular Array when both have the same constructor ?</p>