Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Kotlin Multiplatform

Stefan M.
December 10, 2019

Kotlin Multiplatform

Given at an internal company knowledge sharing meeting.

This presentation is about the "basics" behind Kotlin Multiplatform.

Stefan M.

December 10, 2019
Tweet

More Decks by Stefan M.

Other Decks in Programming

Transcript

  1. Warning: The next slides are not 100% accurate but give

    you a visualisation about how Kotlin Multiplatform works
  2. Fact: Each language has to converted to something which can

    be understand by "a computer". We call these converters compiler.
  3. Fact: Kotlin can be converted to Java Bytecode (via JVM

    compiler) Machine code (via Native compiler) JavaScript (via JS compiler)
  4. fun main() { println("HelloWorld") } Example $ kotlinc HelloWorld.kt -include-runtime

    -d hello.jar $ java -jar hello.jar HelloWorld $ konanc HelloWorld.kt -o hello $ ./hello.kexe HelloWorld $ kotlinc-js HelloWorld.kt -output hello.js $ cat hello.js // JS Code nobody wants to see
  5. Please note that we talk about pure Kotlin code. No

    dependencies to other worlds (like JVM, C or JS).
  6. But - because the compiler knows about other worlds it

    is possible to use the respective dependencies!
  7. Example expect currentTime: Long fun printTime() { println("It is $currentTime

    o'clock") } common.kt // No dependencies to other worlds actual currentTime: Long = java.lang.System.currentTimeMillis() fun main() = printTime() jvm.kt actual currentTime: Long = platform.posix.time(null) fun main() = printTime() native.kt actual currentTime: Long = kotlin.js.Date.now() fun main() = printTime() js.kt