kotlin - 为什么 UInt 没有 toDouble()?

考虑:

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/

相关文章:

parallel-processing - Kotlin 集合的并行操作?

android - RealmObject 的 Kotlin 数据类

java - 为什么以及何时将 @JvmStatic 与伴随对象一起使用?

android - 更新到 Kotlin 1.3.30 会破坏 Dagger 2.21 的构建

gradle - 使用Gradle Kotlin DSL在Gradle中进行样板项目配置

list - Kotlin - 创建具有重复元素的可变列表

kotlin - 如何组织 Kotlin 扩展方法

android - Kotlin:const val 与 val

java - Kotlin 泛型 Array 结果为 "Cannot use T as a r

android - 在库模块中使用 Kotlin,而不在 app 模块中使用它