jbnizet
10/11/2019, 10:28 AMclass Dog {
var frightenedCats = 0
private set
fun frightenCat() {
frightenedCats++
}
}
Here’s the output (I just omitted the constructor) when decompiling the bytecode with `javap -p -c`:
private int frightenedCats;
public final int getFrightenedCats();
Code:
0: aload_0
1: getfield #10 // Field frightenedCats:I
4: ireturn
public final void frightenCat();
Code:
0: aload_0
1: dup
2: getfield #10 // Field frightenedCats:I
5: dup
6: istore_1
7: iconst_1
8: iadd
9: putfield #10 // Field frightenedCats:I
12: return
Note: I’m absolutely fine with that optimization. Just curious about it.Jonathan Shore
10/11/2019, 2:54 PM