Skip to content

Instantly share code, notes, and snippets.

@darichey
Last active May 11, 2020 00:10
Show Gist options
  • Save darichey/e41684455238057ec4deebfc175e803f to your computer and use it in GitHub Desktop.
Save darichey/e41684455238057ec4deebfc175e803f to your computer and use it in GitHub Desktop.
kotlin bad
Compiled from "Test.kt"
public final class com.darichey.test.TestKt {
public static final void main();
Code:
0: iconst_2
1: anewarray #11 // class java/lang/Integer
4: dup
5: iconst_0
6: iconst_m1
7: invokestatic #15 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
10: aastore
11: dup
12: iconst_1
13: iconst_1
14: invokestatic #15 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
17: aastore
18: invokestatic #21 // Method kotlin/collections/CollectionsKt.listOf:([Ljava/lang/Object;)Ljava/util/List;
21: astore_0
22: aload_0
23: checkcast #23 // class java/lang/Iterable
26: astore_2
27: iconst_0
28: istore_3
29: aload_2
30: astore 4
32: new #25 // class java/util/ArrayList
35: dup
36: aload_2
37: bipush 10
39: invokestatic #29 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
42: invokespecial #33 // Method java/util/ArrayList."<init>":(I)V
45: checkcast #35 // class java/util/Collection
48: astore 5
50: iconst_0
51: istore 6
53: aload 4
55: invokeinterface #39, 1 // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
60: astore 7
62: aload 7
64: invokeinterface #45, 1 // InterfaceMethod java/util/Iterator.hasNext:()Z
69: ifeq 127
72: aload 7
74: invokeinterface #49, 1 // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
79: astore 8
81: aload 5
83: aload 8
85: checkcast #51 // class java/lang/Number
88: invokevirtual #55 // Method java/lang/Number.intValue:()I
91: istore 9
93: astore 11
95: iconst_0
96: istore 10
98: iload 9
100: invokestatic #59 // Method foo:(I)Ljava/lang/String;
103: dup
104: ifnull 110
107: goto 112
110: pop
111: aconst_null
112: astore 12
114: aload 11
116: aload 12
118: invokeinterface #63, 2 // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
123: pop
124: goto 62
127: aload 5
129: checkcast #65 // class java/util/List
132: astore_1
133: aload_1
134: iconst_0
135: invokeinterface #69, 2 // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
140: invokevirtual #73 // Method java/lang/Object.toString:()Ljava/lang/String;
143: astore_2
144: iconst_0
145: istore_3
146: getstatic #79 // Field java/lang/System.out:Ljava/io/PrintStream;
149: aload_2
150: invokevirtual #85 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
153: return
public static void main(java.lang.String[]);
Code:
0: invokestatic #9 // Method main:()V
3: return
public static final java.lang.String foo(int);
Code:
0: iload_0
1: ifge 8
4: aconst_null
5: goto 12
8: iload_0
9: invokestatic #105 // Method java/lang/String.valueOf:(I)Ljava/lang/String;
12: areturn
}
fun main() {
val list = listOf(-1, 1)
val newList: List<Any> = list.map {
return@map foo(it) ?: return@map
}
println(newList[0].toString())
}
fun foo(i: Int): String? =
if (i < 0) null else i.toString()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment