title: Kotlin and generics, implementing abstract generic class with generic array
body: <p>I have the following abstract class </p>
  
  <p><code>abstract class Vec2t&lt;T : Number&gt;(open var x: T, open var y: T)</code></p>
  
  <p>implemented by </p>
  
  <p><code>data class Vec2(override var x: Float, override var y: Float) : Vec2t&lt;Float&gt;(x, y)</code></p>
  
  <p>So far, everything works just fine</p>
  
  <p>Now, I'd like to do something similar for the matrices, this is at the moment my abstract class</p>
  
  <p><code>abstract class Mat2t&lt;T : Number&gt;(open var value: Array&lt;out Vec2t&lt;T&gt;&gt;)</code></p>
  
  <p>that should be implemented by</p>
  
  <p><code>class Mat2(override var value: Array&lt;Vec2&gt;) : Mat2t&lt;Float&gt;(value)</code></p>
  
  <p>But compiler complains on <code>Array&lt;Vec2&gt;</code>:</p>
  
  <blockquote>
    <p>Error:(8, 32) Kotlin: Type of 'value' doesn't match the type of the overridden var-property 'public open var value: Array> defined in main.mat.Mat2t'</p>
  </blockquote>
  
  <p>I was told:</p>
  
  <ul>
  <li>I can't change the type of a <code>var</code> property when I override it (but actually I am not really changing it, I am overriding it with a subtype.. is it the same thing?)</li>
  <li><code>mat2.value = object : Vec2t&lt;Float&gt;() { ... }</code> would not be valid, which must not be the case for any subclass of <code>Mat2t&lt;Float&gt;</code></li>
  </ul>
  
  <p>How may I overcome these problems? </p>
  
  <p>Is there a way to have an abstract generic class <code>Mat2t</code> with a generic array and implement it with a subtype array?</p>