2017-10-21 33 views
0

下面的代碼在科特林的js不會編譯:字符串:: toByteArray()不科特林編譯[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科特林編譯編譯:未在科特林/ JS標準庫提供

[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] 
+0

'String.toByteArray()'來自'kotlin-stdlib' /'kotlin-text'。有一個參考呢?根據此頁面:https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.text/to-byte-array.html – cramopy

回答

3

String.toByteArray功能。

The documentation該函數有一個關於平臺和版本要求的部分。那麼這意味着它只能在Kotlin/JVM上使用。

+1

是否有一個原因,爲什麼不在每個平臺上都可用? –