For some reason I’m able to access a property that hasn’t been declared as so.
class FuelTank (
var currentlevel: Double = 0.0,
var minFuel : Double = currentlevel * 10 / 100) {
var lowFuel by Delegates.vetoable(0) {
_, _, new ->
if (new < minFuel ) { println("Fuel Tank too low"); true }
else { false }
}
}
lowFuelhas been declared as a property. Its type hasn’t been specified, but the compiler infers that from the return type of vetoable(), which in turn is inferred from the type of the initial value (0, an Int).
This. All members of a kotlin class are public by default unless declared private. Making lowFuel a top level declaration in your class without specifying the visibility makes it a class property accessible outside the class.