I have the following abstract class
abstract class Vec2t<T : Number>(open var x: T, open var y: T)
implemented by
data class Vec2(override var x: Float, override var y: Float) : Vec2t<Float>(x, y)
So far, everything works just fine
Now, I'd like to do something similar for the matrices, this is at the moment my abstract class
abstract class Mat2t<T : Number>(open var value: Array<out Vec2t<T>>)
that should be implemented by
class Mat2(override var value: Array<Vec2>) : Mat2t<Float>(value)
But compiler complains on Array<Vec2>
:
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'
I was told:
- I can't change the type of a
var
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?) mat2.value = object : Vec2t<Float>() { ... }
would not be valid, which must not be the case for any subclass ofMat2t<Float>
How may I overcome these problems?
Is there a way to have an abstract generic class Mat2t
with a generic array and implement it with a subtype array?