考虑:
val foo: Int = 1
foo.toDouble() // ok
val bar = 2.toUInt()
bar.toDouble() // error!
这对我来说没有意义。为什么 UInt 没有 toDouble
? (它也没有 .toFloat
)。
The docs say :
Every number type supports the following conversions:
- toByte(): Byte
- toShort(): Short
- toInt(): Int
- toLong(): Long
- toFloat(): Float
- toDouble(): Double
- toChar(): Char
所以应该可以。我得到的错误是:
Error:(11, 4) Unresolved reference. None of the following candidates is applicable because of receiver type mismatch:
@InlineOnly public inline fun String.toDouble(): Double defined in kotlin.text
UInt 不被视为数字类型吗?还是别的什么?
最佳答案
根据 this YouTrack request,这似乎将在 1.3.30 中推出.
1.3.30 只是 recently tagged并且似乎很快就会发布。
https://stackoverflow.com/questions/55636856/