Optimization of the compiler public static final and OSGi

I have an OSGi b1 package exporting a class with

public static final String MYVAL = "a"; //version 1

and the second set b2 is compiled and deployed using version 1 of b1.

Later I change the value in b1 to

public static final String MYVAL = "b"; //version 2

but I only recompile and expand b1, b2 does not change or recompile.

Is it possible that b2 still sees the value aat runtime?

+3
source share
1 answer

The value of the referenced static final primitive or string is directly inserted into the usage class. Thus, unrelated to OSGI and any visibility rules, b2it will still contain an embedded value MYVALfor "a".

, Java, 13.4:

(Β§4.12.4), final , , , . , (Β§15.28).

. , , .

public static final String MYVAL = String.valueOf("a");
+6

All Articles