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

Kotlin Dynamic type

coe
September 26, 2023

Kotlin Dynamic type

集まれSwift好き!Swift愛好会 vol.77 @ DeNA
2023/09/26

coe

September 26, 2023
Tweet

More Decks by coe

Other Decks in Technology

Transcript

  1. // x͸Human fun dynamicFun(x: dynamic): Unit { x.back.left.left.up.scratch() } class

    Back { val left: Back get() = Back() val right: Back get() = Back() val up: Back get() = Back() val down: Back get() = Back() fun scratch(): Unit { println(“ຬ଍ʂ”) } } class Human { val back = Back() }
  2. %ZOBNJDUZQF w EZOBNJDܕ w WBMEZOEZOBNJDʜ w ͳΜͰ΋ೖΔ w ܕνΣοΫΛߦΘͳ͍ʢίϯύΠϧΤϥʔʹͳΒͳ͍ʣ w

    ࣗ༝ʹϓϩύςΟ΍ؔ਺Λݺ΂Δ w EZOBNJDܕͷϓϩύςΟ΍ؔ਺ͷϦλʔϯ͸EZOBNJDܕ
  3. fun dynamicPlus(x: dynamic, y: dynamic): Unit { x + y

    // ೔޲ڧ } dynamicPlus(“೔޲”, “ڧ”)
  4. fun dynamicPlus(x: dynamic, y: dynamic): Unit { x + y

    // iOSΤϯδχΞ } dynamicPlus(“iOS”, “ΤϯδχΞ”)
  5. fun dynamicPlus(x: dynamic, y: dynamic): Unit { x + y

    // 105ΤϯδχΞ } dynamicPlus(105, “ΤϯδχΞ”)
  6. %ZOBNJDUZQF w EZOBNJDܕ w WBMEZOEZOBNJDʜ w ͳΜͰ΋ೖΔ w ܕνΣοΫ͸ߦΘͳ͍ʢίϯύΠϧΤϥʔʹͳΒͳ͍ʣ w

    ࣗ༝ʹϓϩύςΟ΍ؔ਺Λݺ΂Δ w EZOBNJDܕͷϓϩύςΟ͸EZOBNJDܕ w EZOBNJDಉ࢜ͷܭࢉ΋Մೳ