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

Hey Kotlin, how it works?

Hey Kotlin, how it works?

Let's dive into Kotlin features and how it works.
I'm keeping updating the slides whenever I got new things. :)

You can find articles on this topic at:
- https://goo.gl/2Tyx4B (eng.)
- https://goo.gl/H9iih9 (kor.)

Chang W. Doh

June 15, 2019
Tweet

More Decks by Chang W. Doh

Other Decks in Technology

Transcript

  1. package com.cwdoh.devfest2017 class Session { val speaker = "cwdoh" val

    title: String = "Kotlin: How it works" var room: Int? = null fun description() = "$speaker's talk: '$title' at room $room" }
  2. package com.cwdoh.devfest2017 class Session { val speaker = "cwdoh" val

    title: String = "Kotlin: How it works" var room: Int? = null fun description() = "$speaker's talk: '$title' at room $room" }
  3. class Session { var name = "cwdoh" } 1SPQFSUZWBS public

    final class Session { @NotNull private String name = "cwdoh"; @NotNull public final String getName() { return this.name; } public final void setName(@NotNull String var1) { Intrinsics.checkParameterIsNotNull(var1, "<set-?>"); this.name = var1; } }
  4. class Session { val name = "cwdoh" } 1SPQFSUZWBM public

    final class Session { @NotNull private final String name = "cwdoh"; @NotNull public final String getName() { return this.name; } }
  5. class Session { val speaker = "cwdoh" fun description() {

    val talks = "$speaker's talks" println(talks) } } -PDBM7BSJBCMF public final class Session { @NotNull private final String speaker = "cwdoh"; @NotNull public final String getSpeaker() { return this.speaker; } public final void description() { String talks = "" + this.speaker + "'s talks"; System.out.println(talks); } }
  6. package com.cwdoh.devfest2017 class Session { val speaker = "cwdoh" val

    title: String = "Kotlin: How it works" var room: Int? = null fun description() = "$speaker's talk: '$title' at room $room" }
  7. class Session { var name: String = "cwdoh" } /PU/VMMQSPQFSUZ

    public final class Session { @NotNull private String name = "cwdoh"; @NotNull public final String getName() { return this.name; } public final void setName(@NotNull String var1) { Intrinsics.checkParameterIsNotNull(var1, "<set-?>"); this.name = var1; } } public static void checkParameterIsNotNull(Object value, String paramName) { if (value == null) { throwParameterIsNullException(paramName); } }
  8. class Session { fun hello(name: String) = "hello, " +

    name } /PU/VMMQBSBNFUFS public final class Session { @NotNull public final String hello(@NotNull String name) { Intrinsics.checkParameterIsNotNull(name, "name"); return "hello, " + name; } } public static void checkParameterIsNotNull(Object value, String paramName) { if (value == null) { throwParameterIsNullException(paramName); } }
  9. class Session { fun hello(name: String) = "hello, " +

    name fun print() { val name: String = "cwdoh" print(hello(name)) } } /PU/VMMMPDBMWBSJBCMFQBSBNFUFS public final class Session { @NotNull public final String hello(@NotNull String name) { Intrinsics.checkParameterIsNotNull(name, "name"); return "hello, " + name; } public final void print() { String name = "cwdoh"; String var2 = this.hello(name); System.out.print(var2); } }
  10. class Session { fun hello(name: String) = "hello, " +

    name fun print() { val name: String? = null print(hello(name!!)) } } .JYFE&YDFQUJPO public final class Session { @NotNull public final String hello(@NotNull String name) { Intrinsics.checkParameterIsNotNull(name, "name"); return "hello, " + name; } public final void print() { String name = (String)null; Intrinsics.throwNpe(); String var2 = this.hello(name); System.out.print(var2); } } NullPointerException?
  11. package com.cwdoh.devfest2017 class Session { val speaker = "cwdoh" val

    title: String = "Kotlin: How it works" var room: Int? = null fun description() = "$speaker's talk: '$title' at room $room" }
  12. class Session { val speaker = "cwdoh" val title: String

    = "Kotlin: How it works" var room: Int? = null fun description() = "$speaker's talk: '$title' at room $room" } 4USJOH5FNQMBUFDPODBUFOBUJPO public final class Session { @NotNull private final String speaker = "cwdoh"; @NotNull private final String title = "Kotlin: How it works"; @Nullable private Integer room; … @NotNull public final String description() { return "" + this.speaker + "'s talk: ‘" + this.title + "' at room " + this.room; } }
  13. #ZUFDPEFPG4USJOH5FNQMBUF4USJOH#VJMEFS // access flags 0x11 public final description()Ljava/lang/String; @Lorg/jetbrains/annotations/NotNull;() //

    invisible L0 LINENUMBER 8 L0 NEW java/lang/StringBuilder DUP INVOKESPECIAL java/lang/StringBuilder.<init> ()V LDC "" INVOKEVIRTUAL java/lang/StringBuilder.append (Ljava/lang/String;)Ljava/lang/StringBuilder; ALOAD 0 GETFIELD com/cwdoh/devfest2017/Session.speaker : Ljava/lang/String; INVOKEVIRTUAL java/lang/StringBuilder.append (Ljava/lang/String;)Ljava/lang/StringBuilder; LDC "'s talk: '" INVOKEVIRTUAL java/lang/StringBuilder.append (Ljava/lang/String;)Ljava/lang/StringBuilder; ALOAD 0 GETFIELD com/cwdoh/devfest2017/Session.title : Ljava/lang/String; INVOKEVIRTUAL java/lang/StringBuilder.append (Ljava/lang/String;)Ljava/lang/StringBuilder; LDC "' at room " INVOKEVIRTUAL java/lang/StringBuilder.append (Ljava/lang/String;)Ljava/lang/StringBuilder; ALOAD 0 GETFIELD com/cwdoh/devfest2017/Session.room : Ljava/lang/Integer; INVOKEVIRTUAL java/lang/StringBuilder.append (Ljava/lang/Object;)Ljava/lang/StringBuilder; INVOKEVIRTUAL java/lang/StringBuilder.toString ()Ljava/lang/String; ARETURN
  14. interface Interface open class OpenClass class ChildClass: OpenClass(), Interface fun

    test() { val child = ChildClass() } 0QFOFEDMBTTJOUFSGBDF JOIFSJUBODF public final class ChildClass extends OpenClass implements Interface {} public interface Interface {} public class OpenClass {} public final class SimpleClassKt { public static final void test() { new ChildClass(); } }
  15. class Person1 constructor(name: String) class Person2(name: String) $POTUSVDUPS public final

    class Person1 { public Person1(@NotNull String name) { Intrinsics.checkParameterIsNotNull(name, "name"); super(); } } public final class Person2 { public Person2(@NotNull String name) { Intrinsics.checkParameterIsNotNull(name, "name"); super(); } }
  16. class Person constructor(val name: String) $POTUSVDUPSXJUIWBMWBS public final class Person

    { @NotNull private final String name; @NotNull public final String getName() { return this.name; } public Person(@NotNull String name) { Intrinsics.checkParameterIsNotNull(name, "name"); super(); this.name = name; } }
  17. class Person constructor(val name: String) { val greetings: String init

    { greetings = "hello, $name” } } *OJUJBM[JFS public final class Person { @NotNull private String greetings; @NotNull private final String name; @NotNull public final String getGreetings() { return this.greetings; } @NotNull public final String getName() { return this.name; } public Person(@NotNull String name) { Intrinsics.checkParameterIsNotNull(name, "name"); super(); this.name = name; this.greetings = "hello, " + this.name; } }
  18. class Person constructor(val name: String) { val greetings: String var

    age: Int = null constructor(name: String, age: Int): this(name) { this.age = age } init { greetings = "hello, $name” } } $POTUSVDUPSEFMFHBUJPO*OJUJBMJ[FS public final class Person { @NotNull private final String greetings; private int age; … public Person(@NotNull String name) { Intrinsics.checkParameterIsNotNull(name, "name"); super(); this.name = name; this.age = ((Number)null).intValue(); this.greetings = "hello, " + this.name; } public Person(@NotNull String name, int age) { Intrinsics.checkParameterIsNotNull(name, "name"); this(name); this.age = age; } }
  19. open class Parent { private val a = println("Parent.a") constructor(arg:

    Unit=println("Parent primary constructor arg")) { println("Parent primary constructor") } init { println("Parent.init") } private val b = println("Parent.b") } class Child : Parent { val a = println("Child.a") init { println("Child.init 1") } constructor(arg: Unit=println("Child primary constructor arg")) : super() { println("Child primary constructor") } val b = println("Child.b") constructor(arg: Int, arg2:Unit= println("Child secondary constructor arg")): this() { println("Child secondary constructor") } init { println("Child.init 2") } } fun main(args: Array<String>) { Child(1) } Child secondary constructor arg Child primary constructor arg Parent primary constructor arg Parent.a Parent.init Parent.b Parent primary constructor Child.a Child.init 1 Child.b Child.init 2 Child primary constructor Child secondary constructor 4PVSDF"OJOEFQUIMPPLBU,PUMJOsTJOJUJBMJ[FST
  20. class Props { var size: Int = 0 val isEmpty:

    Boolean get() = this.size == 0 } $VTUPNHFUUFSTFUUFS public final class Props { private int size; public final int getSize() { return this.size; } public final void setSize(int var1) { this.size = var1; } public final boolean isEmpty() { return this.size == 0; } }
  21. class Props { var age: Int = 0 set(value: Int)

    { age = if (value < 0) 0 else value } } $BVUJPOTUBDLPWFSGMPX public final class Props { private int age; public final int getAge() { return this.age; } public final void setAge(int value) { this.setAge(value < 0? 0:value); } }
  22. class Props { var age: Int = 0 private set

    } TFUUFSHFUUFSNPEJGJFS public final class Props { private int age; public final int getAge() { return this.age; } private final void setAge(int var1) { this.age = var1; } }
  23. &OVN8IFO enum class BlendMode { OPAQUE, TRANSPARENT, FADE, ADD }

    fun blend(b: BlendMode) { when (b) { BlendMode.OPAQUE -> opaque() BlendMode.TRANSPARENT -> transparent() BlendMode.FADE -> fade() BlendMode.ADD -> add() } } public final class EnumTestKt$WhenMappings { // $FF: synthetic field public static final int[] $EnumSwitchMapping$0 = new int[BlendMode.values().length]; static { $EnumSwitchMapping$0[BlendMode.OPAQUE.ordinal()] = 1; $EnumSwitchMapping$0[BlendMode.TRANSPARENT.ordinal()] = 2; $EnumSwitchMapping$0[BlendMode.FADE.ordinal()] = 3; $EnumSwitchMapping$0[BlendMode.ADD.ordinal()] = 4; } } public final class EnumTestKt { public static final void blend(@NotNull BlendMode b) { Intrinsics.checkParameterIsNotNull(b, "b"); switch(EnumTestKt$WhenMappings.$EnumSwitchMapping$0[b.ordinal()]) { case 1: opaque(); break; case 2: transparent(); break; case 3: fade(); break; case 4: add(); } } }
  24. &OVN8IFO enum class BlendMode { OPAQUE, TRANSPARENT, FADE, ADD }

    fun blend(b: BlendMode) { when (b) { BlendMode.OPAQUE -> opaque() BlendMode.TRANSPARENT -> transparent() BlendMode.FADE -> fade() BlendMode.ADD -> add() } } fun blend2(b: BlendMode) { when (b) { BlendMode.FADE -> fade() BlendMode.ADD -> add() BlendMode.TRANSPARENT -> transparent() BlendMode.OPAQUE -> opaque() } } public final class EnumTestKt$WhenMappings { // $FF: synthetic field public static final int[] $EnumSwitchMapping$0 = new int[BlendMode.values().length]; // $FF: synthetic field public static final int[] $EnumSwitchMapping$1; static { $EnumSwitchMapping$0[BlendMode.OPAQUE.ordinal()] = 1; $EnumSwitchMapping$0[BlendMode.TRANSPARENT.ordinal()] = 2; $EnumSwitchMapping$0[BlendMode.FADE.ordinal()] = 3; $EnumSwitchMapping$0[BlendMode.ADD.ordinal()] = 4; $EnumSwitchMapping$1 = new int[BlendMode.values().length]; $EnumSwitchMapping$1[BlendMode.FADE.ordinal()] = 1; $EnumSwitchMapping$1[BlendMode.ADD.ordinal()] = 2; $EnumSwitchMapping$1[BlendMode.TRANSPARENT.ordinal()] = 3; $EnumSwitchMapping$1[BlendMode.OPAQUE.ordinal()] = 4; } }
  25. &OVN8IFO public final static blend(LBlendMode;)V @Lorg/jetbrains/annotations/NotNull;() // invisible, parameter 0

    L0 ALOAD 0 LDC "b" INVOKESTATIC kotlin/jvm/internal/Intrinsics.checkParameterIsNotNull (Ljava/lang/Object;Ljava/lang/String;)V L1 LINENUMBER 9 L1 ALOAD 0 GETSTATIC EnumTestKt$WhenMappings.$EnumSwitchMapping$0 : [I SWAP INVOKEVIRTUAL BlendMode.ordinal ()I IALOAD L2 TABLESWITCH 1: L3 2: L4 3: L5 4: L6 default: L7 L3 LINENUMBER 10 L3 INVOKESTATIC EnumTestKt.opaque ()V GOTO L7 L4 …
  26. 6OTJHOFEJOU @kotlin.ExperimentalUnsignedTypes class UintTest { val a = 42u val

    b = 21u val c = a + b val d = a - b val e = a * b val f = a / b } int var1 = this.a; int var2 = this.b; int var4 = UInt.constructor-impl(var1 + var2); this.c = var4; var1 = this.a; var2 = this.b; var4 = UInt.constructor-impl(var1 - var2); this.d = var4; var1 = this.a; var2 = this.b; var4 = UInt.constructor-impl(var1 * var2); this.e = var4; var1 = this.a; var2 = this.b; var4 = UnsignedKt.uintDivide-J1ME1BU(var1, var2); this.f = var4;
  27. 3BOHFTGPSMPPQ fun testForLoop1() { for (i in 0..10) {} }

    fun testForLoop2() { for (index in 0 until 10) { } } fun testForLoop3() { repeat(10) {} } fun testForLoop4() { (0..10).forEach {} } public final class RangesTestKt { public static final void testForLoop1() { int var0 = 0; for(byte var1 = 10; var0 <= var1; ++var0) { } } public static final void testForLoop2() { int var0 = 0; for(byte var1 = 10; var0 < var1; ++var0) { } } public static final void testForLoop3() { byte var0 = 10; int var1 = 0; for(byte var2 = var0; var1 < var2; ++var1) { } } public static final void testForLoop4() { byte var0 = 0; Iterable $receiver$iv = (Iterable)(new IntRange(var0, 10)); int element$iv; for(Iterator var1 = $receiver$iv.iterator(); var1.hasNext(); element$iv = ((IntIterator)var1).nextInt()) { } } }
  28. 3BOHFTGPSMPPQ fun testForLoopWithStep() { for(i in 0..10 step 2) {

    println(i) } } public static final void testForLoopWithStep() { byte var3 = 0; IntProgression var10000 = RangesKt.step((IntProgression)(new IntRange(var3, 10)), 2); int i = var10000.getFirst(); int var1 = var10000.getLast(); int var2 = var10000.getStep(); if (var2 > 0) { if (i > var1) { return; } } else if (i < var1) { return; } while(true) { System.out.println(i); if (i == var1) { return; } i += var2; } }
  29. class MainActivity : AppCompatActivity() { private var mWelcomeTextView: TextView? =

    null override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) mWelcomeTextView = findViewById(R.id.msgView) as TextView } } :PVSGJSTU"DUJWJUZJO,PUMJOGSPN+BWB
  30. class MainActivity : AppCompatActivity() { private lateinit var mWelcomeTextView: TextView

    override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) mWelcomeTextView = findViewById(R.id.msgView) as TextView } } 3FNPWJOH/VMMBCMFMBUFJOJU
  31. class MainActivity : AppCompatActivity() { private val mWelcomeTextView: TextView override

    fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) // Where am I????? // mWelcomeTextView = // findViewById(R.id.msgView) as TextView } } *GQSPQFSUZWBMVFJTJNNVUBCMFEVSJOH$MBTT-JGFDZDMF
  32. class MainActivity : AppCompatActivity() { private val messageView : TextView

    by lazy { // following code will be executed at first access findViewById(R.id.message_view) as TextView } override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) } fun onSayHello() { messageView.text = "Hello" } } -B[ZJOJUJBMJ[BUJPO
  33. %FDMBSJOHEFMFHBUF class Delegate { operator fun getValue( thisRef: Any?, property:

    KProperty<*> ): String { // do something // return value } operator fun setValue( thisRef: Any?, property: KProperty<*>, value: String ) { // do something // assign } }
  34. class Demo { val myName : String by lazy {

    "John" } } -B[ZJOJUJBMJ[BUJPOCZ-B[Z EFMFHBUJPO public final class Demo { // $FF: synthetic field static final KProperty[] $$delegatedProperties = new KProperty[]{ … }; @NotNull private final Lazy myName$delegate; @NotNull public final String getMyName() { Lazy var1 = this.myName$delegate; KProperty var3 = $$delegatedProperties[0]; return (String)var1.getValue(); } public Demo() { this.myName$delegate = LazyKt.lazy((Function0)null.INSTANCE); } }
  35. class Demo { val myName : String by lazy {

    getNameFromPreference() } } initializer delegate
  36. myName Lazy<T> getValue() { getNameFromPreference() } initializer class Demo {

    val myName : String by lazy { getNameFromPreference() } }
  37. myName Lazy<T> getValue() “John” { getNameFromPreference() } initializer class Demo

    { val myName : String by lazy { getNameFromPreference() } }
  38. myName Lazy<T> getValue() “John” initializer null class Demo { val

    myName : String by lazy { getNameFromPreference() } }
  39. class MainActivity : AppCompatActivity() { private val messageView : TextView

    by lazy { // I’ll be initialized lazily at first access findViewById(R.id.message_view) as TextView } override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) } fun onSayHello() { messageView.text = "Hello" } } #BDLUPDPEF
  40. val messageView: TextView by lazy { findViewById(R.id.message_view) as TextView }

    property delegate ↟MB[Z HFUTMBNCEBGVODUJPO UIFOSFUVSOT-B[Z5 ↟'JSTUHFUUFSDBMMXJMMFYFDVUFTMBNCEBTUPSFSFTVMUJOJUTFMG ↟-BUFSHFUUFSDBMMTKVTUSFUVSOTUPSFEWBMVF
  41. interface Base { fun printX() } class BaseImpl(val x: Int)

    : Base { override fun printX() { print(x) } } *NQMFNFOUBUJPOXJUIJOUFSGBDF
  42. interface A { fun hello(): String } class B :

    A { override fun hello() = "Hello!!" } class C : A by B() $MBTTEFMFHBUJPO $MBTT$IBTEFMFHBUFENFUIPETPGJOTUBODF#  EFGJOFECZJOUFSGBDF"
  43. public interface A { @NotNull String hello(); } public final

    class B implements A { @NotNull public String hello() { return "Hello!!"; } } public final class C implements A { // $FF: synthetic field private final B $$delegate_0 = new B(); @NotNull public String hello() { return this.$$delegate_0.hello(); } } 4BNQMF$MBTTEFMFHBUJPO
  44. fun String.hello() : String { return "Hello, $this" } fun

    main(args: Array<String>) { val whom = "cwdoh" println(whom.hello()) } // Result Hello, cwdoh &YUFOTJPOGVODUJPO
  45. open class C class D: C() fun C.foo() = "c"

    fun D.foo() = "d" fun printFoo(c: C) { println(c.foo()) } class Demo { fun run() { printFoo(D()) } } 3VMF&YUFOTJPOTBSFSFTPMWFETUBUJDBMMZ public class C {} public final class D extends C {} public final class SimpleClassKt { @NotNull public static final String foo(@NotNull C $receiver) { Intrinsics.checkParameterIsNotNull($receiver, "$receiver"); return "c"; } @NotNull public static final String foo(@NotNull D $receiver) { Intrinsics.checkParameterIsNotNull($receiver, "$receiver"); return "d"; } public static final void printFoo(@NotNull C c) { Intrinsics.checkParameterIsNotNull(c, "c"); String var1 = foo(c); System.out.println(var1); } } public final class Demo { public final void run() { SimpleClassKt.printFoo((C)(new D())); } }
  46. class Person { fun hello() { println("hello!") } } fun

    Person.hello() { println("উ֞?!!") } fun main(args: Array<String>) { Person().hello() } // Result hello! 3VMFNFNCFSBMXBZTCFBUTFYUFOTJPOJOTBNFTJHOBUVSF public final class Person { public final void hello() { String var1 = "hello!"; System.out.println(var1); } } public final class SimpleClassKt { public static final void hello(@NotNull Person $receiver) { Intrinsics.checkParameterIsNotNull( $receiver, "$receiver"); String var1 = "উ֞?!!"; System.out.println(var1); } public static final void main(@NotNull String[] args) { Intrinsics.checkParameterIsNotNull(args, "args"); (new Person()).hello(); } }
  47. class D { fun bar() { println("D.bar()") } } class

    C { fun baz() { println("C.bar()") } fun D.foo() { bar() // calls D.bar baz() // calls C.baz } fun caller(d: D) { d.foo() } } 3VMF&YUFOTJPOJTEFDMBSFEJOTDPQF public final class C { public final void baz() { String var1 = "C.bar()"; System.out.println(var1); } public final void foo(@NotNull D $receiver) { Intrinsics.checkParameterIsNotNull($receiver, "$receiver"); $receiver.bar(); this.baz(); } public final void caller(@NotNull D d) { Intrinsics.checkParameterIsNotNull(d, "d"); this.foo(d); } } public final class D { public final void bar() { String var1 = "D.bar()"; System.out.println(var1); } }
  48. data class Length(var centimeters: Int = 0) var Length.meters: Float

    get() { return centimeters / 100.0f } set(meters: Float) { this.centimeters = (meters * 100.0f).toInt() } &YUFOTJPOQSPQFSUZ
  49. &YUFOTJPO1SPQFSUZEPFTOsUEFDMBSFBGJFME  CVUKVTUBDDFTTJOUFSGBDF data class Length(var centimeters: Int = 0)

    var Length.meters: Float get() { return centimeters / 100.0f } set(meters: Float) { this.centimeters = (meters * 100.0f).toInt() } public final class Length { private int centimeters; ... } public final class ExtensionsKt { public static final float getMeters( @NotNull Length $receiver) { Intrinsics.checkParameterIsNotNull($receiver, "$receiver"); return (float)$receiver.getCentimeters() / 100.0F; } public static final void setMeters( @NotNull Length $receiver, float meters) { Intrinsics.checkParameterIsNotNull($receiver, "$receiver"); $receiver.setCentimeters((int)(meters * 100.0F)); } ... }
  50. fun Any?.toString(): String { if (this == null) return “null"

    return toString() } /VMMBCMFSFDFJWFS public final class SimpleClassKt { @NotNull public static final String toString(@Nullable Object $receiver) { return $receiver == null? "null":$receiver.toString(); } }
  51. fun Any?.toString(): String { println("Extension is called.") if (this ==

    null) return "null" return toString() } fun main(args: Array<String>) { val var1 : Any? = null println(var1.toString()) val str1 : String? = null println(str1.toString()) var str2 : String? = "hello" println(str2.toString()) var str3 : String = "world" println(str3.toString()) } $"65*0//VMMBCMFSFDFJWFSCFBUTNFNCFS public final class SimpleClassKt { @NotNull public static final String toString(@Nullable Object $receiver) { String var1 = "Extension is called."; System.out.println(var1); return $receiver == null?"null":$receiver.toString(); } public static final void main(@NotNull String[] args) { Intrinsics.checkParameterIsNotNull(args, “args"); Object var1 = null; String str1 = toString(var1); System.out.println(str1); str1 = (String)null; String str2 = toString(str1); System.out.println(str2); str2 = "hello"; String str3 = toString(str2); System.out.println(str3); str3 = "world"; String var5 = str3.toString(); System.out.println(var5); } } Extension is called. null Extension is called. null Extension is called. hello world
  52. OPJOMJOFGVODUJPO fun sing() { println("We will we will rock you")

    println("(Sing it!)") println("We will we will rock you") } fun beatbox() { println("pv zk bschk pv zk") } fun ensemble() { sing() beatbox() sing() beatbox() } public final class SimpleClassKt { public static final void sing() { String var0 = "We will we will rock you"; System.out.println(var0); var0 = "(Sing it!)"; System.out.println(var0); var0 = "We will we will rock you"; System.out.println(var0); } public static final void beatbox() { String var0 = "pv zk bschk pv zk"; System.out.println(var0); } public static final void ensemble() { sing(); beatbox(); sing(); beatbox(); } }
  53. JOMJOFGVODUJPO fun sing() { println("We will we will rock you")

    println("(Sing it!)") println("We will we will rock you") } fun beatbox() { println("pv zk bschk pv zk") } fun ensemble() { sing() beatbox() sing() beatbox() } public final class SimpleClassKt { public static final void sing() { String var1 = "We will we will rock you"; … } public static final void beatbox() { … } public static final void ensemble() { String var0 = "We will we will rock you"; System.out.println(var0); var0 = "(Sing it!)"; System.out.println(var0); var0 = "We will we will rock you"; System.out.println(var0); beatbox(); var0 = "We will we will rock you"; System.out.println(var0); var0 = "(Sing it!)"; System.out.println(var0); var0 = "We will we will rock you"; System.out.println(var0); beatbox(); } }
  54. fun log(message: () -> String) { println(message()) } fun test()

    { log { "Lorem ipsum dolor sit amet, consectetur ..." } } -PHHJOH public final class SimpleClassKt { public static final void log(@NotNull Function0 message) { Intrinsics.checkParameterIsNotNull(message, "message"); Object var1 = message.invoke(); System.out.println(var1); } public static final void test() { log((Function0)null.INSTANCE); } }
  55. inline fun trace(message: String) {} fun doSomething() { print("I'm doing

    something!") trace("doSomething() is doing something!") } FNQUZJOMJOFGVODUJPO public final class SimpleClassKt { public static final void trace(@NotNull String message) { Intrinsics.checkParameterIsNotNull(message, "message"); } public static final void doSomething() { String var0 = "I'm doing something!"; System.out.print(var0); var0 = "doSomething() is doing something!"; } }
  56. &OVN8IFO inline class Color(private val c: Int) { val a

    get() = (c shr 24) and 0xff val r get() = (c shr 16) and 0xff val g get() = (c shr 8) and 0xff val b get() = (c ) and 0xff } fun test() { val a = Color(0x7f_10_20_30) val b = Color(0x7f_30_20_10) println(a == b) println(a.equals(b)) } public final class InlineClassKt { public static final void test() { int a = Color.constructor-impl(2131763248); int b = Color.constructor-impl(2133860368); boolean var2 = Intrinsics.areEqual( Color.box-impl(a), Color.box-impl(b)); System.out.println(var2); var2 = Color.equals-impl(a, Color.box-impl(b)); System.out.println(var2); } }
  57. *OJUJBMJ[JOH"SSBZ var arr1 = intArrayOf(0, 1, 2) var arr2 =

    arrayOf(0, 1, 2) var arr3 = IntArray(3) { it } @NotNull private static int[] arr1 = new int[]{0, 1, 2}; @NotNull private static Integer[] arr2 = new Integer[]{0, 1, 2}; @NotNull private static int[] arr3; static { int size$iv = 3; int[] result$iv = new int[size$iv]; int i$iv = 0; for(int var3 = result$iv.length; i$iv < var3; result$iv[i$iv] = i$iv++) { } arr3 = result$iv; }
  58. JOMJOFGVODUJPO public class Widget { public interface Listener { void

    onEvent(Widget widget); } private int listenerCount = 0; public int getListenerCount() { return listenerCount; } public void addListener(Listener listener) {} public void removeListener(Listener listener) {} } val w = Widget() val listener = { widget: Widget -> println("Listened to $widget") } w.addListener(listener) println(w.listenerCount) w.removeListener(listener) println(w.listenerCount)
  59. fun fetchUserDetail(id: String) { val token = auth() val user

    = getUser(token, id) updateUserData(user) } BVUI Waaaaa~~it HFU6TFS VQEBUF6TFS%BUB 8BBBBB__JU
  60. fun fetchUserDetail(id: String) { auth { token -> getUser(token) {

    updateUserData(it) } } } BVUI HFU6TFS VQEBUF6TFS%BUB
  61. suspend fun fetchUserDetail(id: String) { val token = auth() val

    user = getUser(token, id) updateUserData(user) } suspend BVUI *%-& /POCMPDLJOH HFU6TFS VQEBUF6TFS%BUB *%-& /POCMPDLJOH
  62. fun plusOne(initial: Int) : Int { val ONE = 1

    var result = initial result += ONE return result } 4UBUF
  63. suspend fun fetchUserDetail(id: String) { val token = auth() val

    user = getUser(token, id) updateUserData(user) } }
  64. suspend fun fetchUserDetail(id: String) { // ... switch (label) {

    case 0: val token = auth() case 1: val user = getUser(token, id) case 2: updateUserData(user) } }
  65. fun fetchUserDetail(id: String) { // ... switch (label) { case

    0: val token = auth() case 1: val user = getUser(token, id) case 2: updateUserData(user) } } -BCFMJOH
  66. fun fetchUserDetail(id: String, cont: Continuation) { switch ( label) {

    case 0: auth( ) case 1: getUser(token, id ) case 2: … } } val sm = object : CoroutineImpl { ... } sm. sm , sm 4UBUF.BDIJOF
  67. fun fetchUserDetail(id: String, cont: Contiunation) { val sm = object

    : CoroutineImpl { ... } switch (sm.label) { case 0: auth(sm) case 1: getUser(token, id, sm) case 2: … } } $POUJOVBUJPO
  68. fun fetchUserDetail(id: String, cont: Contiunation) { val sm = object

    : CoroutineImpl { ... } switch (sm.label) { case 0: sm.id = id sm.label = 1 auth(sm) … } } 4BWFTUBUFT
  69. fun fetchUserDetail(id: String, cont: Contiunation) { val sm = object

    : CoroutineImpl { ... } switch (sm.label) { … case 1: val id = sm.id val token = sm.result as String sm.label = 2 getUser(token, id, sm) … } 3FTUPSFTUBUF
  70. fun fetchUserDetail(id: String, cont: Contiunation) { val sm = object

    : CoroutineImpl { fun resume(...) { fetchUserDetail(null, this) } } switch (sm.label) { case 0: … } } 3FTVNF DBMMCBDL
  71. fun fetchUserDetail(id: String, cont: Contiunation) { val sm = cont

    as? ThisSM ?: object : CoroutineImpl { fun resume(...) { fetchUserDetail(null, this) } } switch (sm.label) { case 0: … } } $POUJOVBUJPO SFVTF