If you want to use a data class you can use this workaround
data class Direction(var vector_: Vector3D) {
init {
vector_ = vector_.normalize()
}
val vector = vector_
}
not the best but the data class relies on the modified version of your vector. The name in the constructor is slightly different but you can’t access vector
in the constructor so no error can be made and you don’t lose the power of the data class (hash and equals) nor the immutability