javascript - String::toByteArray() 无法在 Kotlin [js] 中编译

标签 javascript kotlin kotlin-interop

以下代码无法在 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]

最佳答案

Kotlin/JS 标准库中未提供

String.toByteArray 函数。

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

关于javascript - String::toByteArray() 无法在 Kotlin [js] 中编译,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46862726/

相关文章:

javascript - 自Javascript中的unix时代以来,如何以毫秒为单位获取时间?

javascript - ajaxt奇怪的错误: Uncaught SyntaxError: Unexpected token if

c - 互操作 C 库时为 "Unresolved Reference"

android - 程序类型已经存在:com.hlab.fabrevealmenu.model.FABMenuItem

Kotlin 构造函数委托(delegate)给内部数据类?

kotlin - 为什么 `Intrinsics.checkParameterIsNotNull` 没有内联?

javascript - jQuery-Ajax : insert data from php

javascript - 用户单击提交时等待指示器

java - 运行应用程序时,Intellij 不包括对类路径的 gradle 依赖

java - 从 java 类调用 kotlin 函数会产生错误