2017-10-21 71 views
0

Le code suivant ne compile pas Kotlin Js:String :: toByteArray() ne compile pas Kotlin [js]

"My String".toByteArray() 

Toutes les idées pourquoi?

L'erreur renvoyée est:

[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: 

Le même code compile dans la compilation Kotlin non javascript:

[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()' provient de 'kotlin-stdlib' /' kotlin-text'. Avez-vous inclus une référence à ce sujet? Selon cette page: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.text/to-byte-array.html – cramopy

Répondre

3

fonction String.toByteArray n'est pas fourni dans la bibliothèque standard Kotlin/JS.

The documentation de cette fonction a une section sur les exigences de la plate-forme et de la version. JVM signifie qu'il n'est disponible que sur Kotlin/JVM.

+1

Y a-t-il une raison pourquoi n'est-ce pas disponible sur toutes les plateformes? –