变量INT,getter DOUBLE

Pro*_*mer 0 getter kotlin

如果变量是int,是否可以在kotlin中设置getter以返回int的双重insted?

没有宣布新的功能.

var x = 0
    get() = x.toDouble()
Run Code Online (Sandbox Code Playgroud)

zsm*_*b13 7

如果要将变量公开为与实际不同的类型,则需要支持属性:

private var _x = 0

val x: Double
    get() = _x.toDouble()
Run Code Online (Sandbox Code Playgroud)