Search code examples
javascriptjavacollectionskotlinstandard-library

Use Java Standard Lib for Kotlin when compiling to Javascript


I have implemented a library in Kotlin for use in the browser. When I compile it to Javascript, the dependencies from the Java standard lib, e.g. collection classes like PriorityQueue, are not found.

Is it possible to convince the compiler to find and compile these classes as well, or is there a precompiled Javascript-Java standard lib, or do I have to use the Kotlin standard lib only?


Solution

  • You have to use the Kotlin standard library only. The Kotlin -> js compiler has no way to turn java libraries (or any jar) into javascript.

    I'm not as familiar with the efforts for Kotlin, but the scala.js community has ported many standard java library features to scala.js to ease the transition between the jvm and the web browser. Something similar would need to happen for Kotlin for the specific features you want to use.

    You can however reference javascript from kotlin: https://blog.jetbrains.com/kotlin/2014/12/javascript-interop/