【问题标题】:String::toByteArray() does not compile in Kotlin [js]String::toByteArray() 在 Kotlin [js] 中无法编译
【发布时间】:2017-10-21 11:22:00
【问题描述】:

以下代码在 Kotlin Js 中无法编译:

"My String".toByteArray()

有什么想法吗?

返回的错误是:

[INFO]
[INFO] --- kotlin-maven-plugin:1.1.51:js (compile-js) @ client ---
[INFO] Kotlin version 1.1.51 (JRE 1.8.0_144-b01)
[INFO] Compiling Kotlin sources from [C:\myproject\src\main\kotlin]
[ERROR] C:\myproject\src\main\kotlin\mypackage\MyFile.kt: (15, 48) Unresolved reference. None of the following candidates is applicable because of receiver type mismatch:
public fun Array<out Byte>.toByteArray(): ByteArray defined in kotlin.collections
public fun Collection<Byte>.toByteArray(): ByteArray defined in kotlin.collections
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:

同样的代码在非javascript Kotlin编译中编译:

[INFO] --- kotlin-maven-plugin:1.1.51:compile (compile) @ client ---
[INFO] Kotlin version 1.1.51 (JRE 1.8.0_144-b01)
[INFO] Compiling Kotlin sources from [C:\myproject\src\main\kotlin, C:\myproject\src\main\java]
[INFO] Module name is client
[INFO]

【问题讨论】:

标签: javascript kotlin kotlin-interop


【解决方案1】:

String.toByteArray 函数在 Kotlin/JS 标准库中没有提供。

The documentation 该函数有一个关于平台和版本要求的部分。 JVM 意味着它只在 Kotlin/JVM 上可用。

【讨论】:

  • 它不是在每个平台上都可用的原因吗?
猜你喜欢
  • 2020-04-18
  • 2018-11-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-11-24
  • 1970-01-01
  • 1970-01-01
  • 2016-09-21
相关资源
最近更新 更多