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
<!-- Copyright 2019 Google LLC. | |
SPDX-License-Identifier: Apache-2.0 --> | |
class SomeClass { | |
//… | |
companion object { | |
private var count: Int = 0 | |
fun count() { | |
count++ | |
} |
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
<!-- Copyright 2019 Google LLC. | |
SPDX-License-Identifier: Apache-2.0 --> | |
public final class AnotherClass { | |
private static int count; | |
public static final AnotherClass.Counter Counter = new AnotherClass.Counter((DefaultConstructorMarker)null); | |
public static final class Counter { | |
public final void count() { | |
AnotherClass.count = AnotherClass.count + 1; |
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
<!-- Copyright 2019 Google LLC. | |
SPDX-License-Identifier: Apache-2.0 --> | |
val tempValues = object : { | |
var value = 2 | |
var anotherValue = 3 | |
var someOtherValue = 4 | |
} | |
tempValues.value += tempValues.anotherValue |
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
<!-- Copyright 2019 Google LLC. | |
SPDX-License-Identifier: Apache-2.0 --> | |
<undefinedtype> tempValues = new Object() { | |
private int value = 2; | |
private int anotherValue = 3; | |
private int someOtherValue = 4; | |
// getters and setters for x, y, z | |
//... |
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
<!-- Copyright 2019 Google LLC. | |
SPDX-License-Identifier: Apache-2.0 --> | |
val t1 = Thread(object : Runnable { | |
override fun run() { | |
//do something | |
} | |
}) | |
t1.start() |
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
public final void call() { | |
float value = 123643.0F; | |
int $i$f$calculate = false; | |
KClass var5 = Reflection.getOrCreateKotlinClass(Integer.class); | |
Integer var10000; | |
if (Intrinsics.areEqual(var5, Reflection.getOrCreateKotlinClass(Float.TYPE))) { | |
var10000 = (Integer)value; | |
} else { | |
if (!Intrinsics.areEqual(var5, Reflection.getOrCreateKotlinClass(Integer.TYPE))) { | |
throw (Throwable)(new IllegalStateException("Only works with Float and Int")); |
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
inline fun <reified T> calculate(value: Float): T { | |
return when (T::class) { | |
Float::class -> value as T | |
Int::class -> value.toInt() as T | |
else -> throw IllegalStateException("Only works with Float and Int") | |
} | |
} | |
val intCall: Int = calculate(123643) | |
val floatCall: Float = calculate(123643) |
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
// Inline function converted to Java from byte code | |
public static final void printType() { | |
int $i$f$printType = 0; | |
Intrinsics.reifiedOperationMarker(4, "T"); | |
Class var1 = Object.class; | |
boolean var2 = false; | |
System.out.print(var1); | |
} | |
// Caller converted to Java from byte code |
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
inline fun <reified T> printType() { | |
print(T::class.java) | |
} | |
fun printStringType(){ | |
//calling the reified generic function with String type | |
printType<String>() | |
} |
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
List list = new ArrayList(); | |
list.add("First String"); | |
list.add(6); // No error |