Last active
March 28, 2017 16:24
-
-
Save deanveloper/f4f6051616375e88aad339908ee8fb96 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// the A in front of the file name is just to keep this on top in the gist lol | |
inline fun <reified T> testReified(obj: T) { | |
// None of these are possible in Java because of Type Erasure | |
if (obj is Int) { | |
println(5 + obj) | |
} else { | |
println(obj) | |
} | |
val x = 5 | |
if (x is T) { | |
println("5 is type T") | |
} | |
} | |
fun main(args: Array<String>) { | |
testReified(5) | |
testReified("5") | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This file is a file that I have changed manually | |
// to simplify the decompiled code above. Note that | |
// some parts may look much different from the decompiled | |
// code because of two reasons: | |
// 1. The decompiler bugs out certain optimizations | |
// 2. To make the inlined calls look more like how the inline function actually looks | |
// First inlined call: testReified(5). Output: 10, "5 is type T" | |
Object param = Integer.valueOf(5); | |
if (param instanceof Integer) { | |
System.out.println(5 + ((int) param)); // 10 | |
} else { | |
System.out.println(param); | |
} | |
int x = 5; | |
if(Integer.valueOf(x) instanceof Integer) { | |
System.out.println("5 is type T"); // outputs | |
} | |
// Second inlined call: testReified("5"). Output: 5 | |
Object param2 = "5"; | |
if(param2 instanceof Integer) { | |
System.out.println(5 + ((int) param)); | |
} else { | |
System.out.println(param2); // "5" | |
} | |
int x = 5; | |
if(Integer.valueOf(x) instanceof String) { | |
var3 = "5 is type T"; | |
System.out.println(var3); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import kotlin.Metadata; | |
import kotlin.jvm.internal.Intrinsics; | |
import org.jetbrains.annotations.NotNull; | |
@Metadata( | |
mv = {1, 1, 5}, | |
bv = {1, 0, 1}, | |
k = 2, | |
d1 = {"\u0000\u0014\n\u0000\n\u0002\u0010\u0002\n\u0000\n\u0002\u0010\u0011\n\u0002\u0010\u000e\n\u0002\b\u0006\u001a\u0019\u0010\u0000\u001a\u00020\u00012\f\u0010\u0002\u001a\b\u0012\u0004\u0012\u00020\u00040\u0003¢\u0006\u0002\u0010\u0005\u001a\u001e\u0010\u0006\u001a\u00020\u0001\"\u0006\b\u0000\u0010\u0007\u0018\u00012\u0006\u0010\b\u001a\u0002H\u0007H\u0086\b¢\u0006\u0002\u0010\t¨\u0006\n"}, | |
d2 = {"main", "", "args", "", "", "([Ljava/lang/String;)V", "testReified", "T", "obj", "(Ljava/lang/Object;)V", "production sources for module Test"} | |
) | |
public final class TestReifiedKt { | |
private static final void testReified(Object obj) { | |
if(obj instanceof Integer) { | |
int var2 = 5 + ((Number)obj).intValue(); | |
System.out.println(var2); | |
} else { | |
System.out.println(obj); | |
} | |
int x = true; | |
Intrinsics.reifiedOperationMarker(3, "T"); | |
if(true) { | |
String var3 = "5 is type T"; | |
System.out.println(var3); | |
} | |
} | |
public static final void main(@NotNull String[] args) { | |
Intrinsics.checkParameterIsNotNull(args, "args"); | |
Object obj$iv = Integer.valueOf(5); | |
int var2; | |
if(obj$iv instanceof Integer) { | |
var2 = 5 + ((Number)obj$iv).intValue(); | |
System.out.println(var2); | |
} else { | |
System.out.println(obj$iv); | |
} | |
int x$iv = true; | |
String var3; | |
if(true) { | |
var3 = "5 is type T"; | |
System.out.println(var3); | |
} | |
Object obj$iv = "5"; | |
if(obj$iv instanceof Integer) { | |
var2 = 5 + ((Number)obj$iv).intValue(); | |
System.out.println(var2); | |
} else { | |
System.out.println(obj$iv); | |
} | |
int x$iv = 5; | |
if(Integer.valueOf(x$iv) instanceof String) { | |
var3 = "5 is type T"; | |
System.out.println(var3); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment