变量 INT, getter DOUBLE
Variable INT, getter DOUBLE
如果变量是 int,是否可以将 kotlin 中的 getter 设置为 return int 的 double insted?
当然没有声明新函数。
var x = 0
get() = x.toDouble()
如果您想将变量公开为与实际不同的类型,则需要 backing property:
private var _x = 0
val x: Double
get() = _x.toDouble()
如果变量是 int,是否可以将 kotlin 中的 getter 设置为 return int 的 double insted?
当然没有声明新函数。
var x = 0
get() = x.toDouble()
如果您想将变量公开为与实际不同的类型,则需要 backing property:
private var _x = 0
val x: Double
get() = _x.toDouble()