I am trying to understand why in a class this is possible:
var relevantPoint: Point
private set // this works
init {
if (points.size < 3) // doing validation
throw IllegalArgumentException("Incomplete Data!")
relevantPoint = points.first() // here the point gets initialized
}
but not this:
var relevantPoint: Point
private set(value) { // Why can't I do this? -> "Property must be initialized - Error"
field = value // actually redundant unless more functionality applies
}
init {
if (points.size < 3) // doing validation
throw IllegalArgumentException("Incomplete Data!")
relevantPoint = points.first() // here the point gets initialized
}
In both cases the init { } will initialize the var.
Is this possibly a wrong check in the compiler?