Kotlin 变量INT,getter-DOUBLE
如果变量是int,是否可以在kotlin中设置getter以返回双精度int 当然,不需要声明新函数Kotlin 变量INT,getter-DOUBLE,kotlin,getter,Kotlin,Getter,如果变量是int,是否可以在kotlin中设置getter以返回双精度int 当然,不需要声明新函数 var x = 0 get() = x.toDouble() 如果要将变量公开为与实际不同的类型,则需要: private var _x = 0 val x: Double get() = _x.toDouble()
var x = 0
get() = x.toDouble()
如果要将变量公开为与实际不同的类型,则需要:
private var _x = 0
val x: Double
get() = _x.toDouble()