Open
Description
object Foo {
final val spartiates = 300
val leonidasses = 1
}
object Bar {
def spartiates: Int = Foo.spartiates
def leonidasses: Int = Foo.leonidasses
}
Produces in Bar.class:
public int spartiates();
Code:
0: sipush 300
3: ireturn
public int leonidasses();
Code:
0: getstatic #21 // Field im/tox/tox4j/crypto/Foo$.MODULE$:Lim/tox/tox4j/crypto/Foo$;
3: invokevirtual #23 // Method im/tox/tox4j/crypto/Foo$.leonidasses:()I
6: ireturn
and in Foo.class:
public final int spartiates();
Code:
0: sipush 300
3: ireturn
public int leonidasses();
Code:
0: aload_0
1: getfield #19 // Field leonidasses:I
4: ireturn
The (private final) field leonidasses is initialised to 1 in the constructor.
The problem here is that for the "final val" case, it is a compile time constant and it's immediately constant-folded into the call site, causing 0% coverage on this code, even when explicitly called from Java (which does not do constant folding for these calls).