The class A
declares a constant C
as follows:
public class A {
public static final int C = 10;
}
This constant is used in method M
of class B
as follows:
public class B {
public int M() {
return A.C;
}
}
In the bytecodes of class B
, the method M
looks like this:
public other()I
L0
LINENUMBER 29 L0
BIPUSH 10
IRETURN
L1
LOCALVARIABLE this Lcalc/B; L0 L1 0
MAXSTACK = 1
MAXLOCALS = 1
So, there is no reference to class A
anywhere in the bytecode because the Java compiler optimizes constant expressions at compile time (look this related question).
How to avoid this phenomenon in order to collect the usage of class A
by class B
?