So I have a simple class in kotlin and a function that gets a field from that class:
class SomeClass {
var value = 1
}
fun showValue() {
val klass = SomeClass()
println(klass.value)
}
A function bytecode would look like this:
public final static showValue()V
L0
LINENUMBER 8 L0
NEW com/korol/kittybot/SomeClass
DUP
INVOKESPECIAL com/korol/kittybot/SomeClass.<init> ()V
ASTORE 0
L1
LINENUMBER 9 L1
ALOAD 0
INVOKEVIRTUAL com/korol/kittybot/SomeClass.getValue ()I
ISTORE 1
GETSTATIC java/lang/System.out : Ljava/io/PrintStream;
ILOAD 1
INVOKEVIRTUAL java/io/PrintStream.println (I)V
L2
LINENUMBER 10 L2
RETURN
L3
LOCALVARIABLE klass Lcom/korol/kittybot/SomeClass; L1 L3 0
MAXSTACK = 2
MAXLOCALS = 2
For some reason, getter is not static. INVOKEVIRTUAL com/korol/kittybot/SomeClass.getValue
. I am interested in why. As far as I understand virtual calls are for functions with several implementations. But here the field is not open and the class is neither abstract nor open. Would appreciate if someone can explain it.