Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

$ kotlinc Foo.kt
$ javap -c Foo > bytecode_kotlin.txt
$ javac Foo.java
$ javap -c Foo > bytecode_java.txt
Compiled from "Bar.kt"
public final class Bar {
public final boolean is valid();
Code:
0: aload_0
1: getfield #10 // Field "is valid":Z
4: ireturn
public final boolean is_valid();
Code:
Compiled from "Foo.kt"
public final class Foo {
public final int getNumber();
Code:
0: aload_0
1: getfield #10 // Field isValid:Z
4: ifeq 11
7: iconst_1
8: goto 12
Compiled from "Foo.java"
public final class Foo {
public final int getNumber();
Code:
0: aload_0
1: invokevirtual #5 // Method java/lang/Object.getClass:()Ljava/lang/Class;
4: pop
5: iconst_1
6: ireturn
public final class Bar {
private final boolean is valid = true;
private final boolean is_valid = true;
public final boolean is_valid/* $FF was: is valid*/() {
return this.is valid;
}
public final boolean is_valid() {
return this.is_valid;
class Bar {
val `is valid` = true
val is_valid = true
}
public final class Foo {
private final int product = this.getNumber() * 2;
private final boolean isValid = true;
public final int getNumber() {
return this.isValid ? 1 : 0;
}
public final int getProduct() {
return this.product;
class Foo {
val number
get() = if (isValid) 1 else 0
val product = number * 2
val isValid = true
}
abstract class PrefDelegate<T>(val prefKey: String) {
companion object {
private var context: Context? = null
/**
* Initialize PrefDelegate with a Context reference
* This method needs to be called before any other usage of PrefDelegate
*/
fun init(context: Context) {