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

Kotlin Everywhere

Kotlin Everywhere

Roberto Orgiu

July 20, 2018
Tweet

More Decks by Roberto Orgiu

Other Decks in Technology

Transcript

  1. • JavaFX • Beautiful DSL • UI + Background thread

    • Injection • REST • Field validation • Can work™ with JS TornadoFX 6
  2. Kotlin Native COMMON no platform specific dependencies class/function declaration 9

    PLATFORM implementations of platform-dependent declarations in the common module always an implementation of a single common module REGULAR targets specific platform can be dependency of platform modules can depend on platform modules
  3. 10

  4. 12 actual ◇ platform module provides actual declarations ◇ actual

    declarations must match expected declarations
  5. 13 package org.jetbrains.foo expect class Foo(bar: String) { fun frob()

    } fun main(args: Array<String>) { Foo("Hello").frob() }
  6. 14 package org.jetbrains.foo actual class Foo actual constructor(val bar: String)

    { actual fun frob() { println("Frobbing the $bar") } }
  7. 16

  8. 18

  9. 19

  10. ◇ You can set and call everything you want on

    properties of this type ◇ Disables compiler checks (beware of runtime errors) 20 dynamic
  11. ◇ Kotlin assumes the implementation is provided by the developer

    (in JS) ◇ The compiler will not generate JS code for this function ◇ No auto completion 21 external
  12. 22 external fun require(module: String): dynamic fun main(args: Array<String>) {

    val app = require(“express”) app.get(“/hello”, {req, res -> res.send(“Hello world!”) }) }
  13. 24 @JsModule(“express”) external class Express { fun get( route: String,

    callback: (req: Request, res: Response) -> Unit ) external class Request external class Response { fun send(data: String) } }