Instantiation issue


#1

I have

data class Vec3i(
  override var x: Int = 0,
  override var y: Int = 0,
  override var z: Int = 0
) : Vec3t(x, y, z)

thas has as one secondary constructor as follow:

constructor(v: Vec3t<Number>) : this(v.x.toInt(), v.y.toInt(), v.z.toInt())

and

data class Vec3ub(
  override var x: Ubyte = Ubyte(0),
  override var y: Ubyte = Ubyte(0), 
  override var z: Ubyte = Ubyte(0)
) : Vec3t(x, y, z)

Where Vec3t is

abstract class Vec3t<T : Number>(
  override var x: T, 
  override var y: T, 
  open var z: T
) : Vec2t(x, y)

And Ubyte extends Number

Why can’t I instantiate a Vec3i from a Vec3ub then?

Vec3i(vec3ub)


#2

What do you mean by “can’t”? What happens if you try?


#3

Sorry, I meant the compiler doesn’t find any suitable constructor

However, I just found out, I missed the out keyword in the constructor