Skip to content

Instantly share code, notes, and snippets.

@h0tk3y
Last active December 11, 2017 19:01
Show Gist options
  • Save h0tk3y/546bf65837f65c27f7ab8e0926b2074e to your computer and use it in GitHub Desktop.
Save h0tk3y/546bf65837f65c27f7ab8e0926b2074e to your computer and use it in GitHub Desktop.
// Kotlin:
abstract class Abstract {
abstract val abc: String
init {
println(javaClass.name + ": " + abc)
}
}
object Object : Abstract() {
override val abc: String = "abc"
}
// Bytecode of `Object`:
// access flags 0x1
public getAbc()Ljava/lang/Object;
@Lorg/jetbrains/annotations/NotNull;() // invisible
L0
LINENUMBER 35 L0
GETSTATIC abc/Object.abc : Ljava/lang/Object; <- the getter returns the value of the static field
ARETURN
// access flags 0x2
private <init>()V
L0
LINENUMBER 34 L0
ALOAD 0
L1
LINENUMBER 34 L1
INVOKESPECIAL abc/Abstract.<init> ()V // <- calls super constructor
RETURN
L2
LOCALVARIABLE this Labc/Object; L0 L2 0
MAXSTACK = 1
MAXLOCALS = 1
// access flags 0x8
static <clinit>()V
L0
LINENUMBER 34 L0
NEW abc/Object
DUP
INVOKESPECIAL abc/Object.<init> ()V <- calls `Object`'s constructor
ASTORE 0
ALOAD 0
PUTSTATIC abc/Object.INSTANCE : Labc/Object;
L1
LINENUMBER 35 L1
LDC "abc"
PUTSTATIC abc/Object.abc : Ljava/lang/String; <- puts the value into the static field
RETURN
MAXSTACK = 2
MAXLOCALS = 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment