title: is it possible to disable javac's inlining of static final variables?
body: <p>The Java static compiler (javac) inlines some static final variables and brings the values directly to the constant pool. Consider the following example. Class A defines some constants (public static final variables):</p>
  
  <pre><code>public class A {
      public static final int INT_VALUE = 1000;
      public static final String STRING_VALUE = "foo";
  }
  </code></pre>
  
  <p>Class B uses these constants:</p>
  
  <pre><code>public class B {
      public static void main(String[] args) {
          int i = A.INT_VALUE;
          System.out.println(i);
          String s = A.STRING_VALUE;
          System.out.println(s);
      }
  }
  </code></pre>
  
  <p>When you compile class B, javac gets the values of these constants from class A and inlines these values in B.class. As a result, the dependency B had to class A at the compile time is erased from the bytecode. This is a rather peculiar behavior because you are baking in the values of these constants <strong>at the time of compilation</strong>. And you would think that this is one of the easiest things that the JIT compiler can do at runtime.</p>
  
  <p>Is there any way or any hidden compiler option that lets you disable this inlining behavior of javac? For the background, we're looking into doing bytecode analysis for dependency purposes, and it is one of the few cases where bytecode analysis fails to detect compile-time dependencies. Thanks!</p>
  
  <p><strong>Edit</strong>: this is a vexing issue because normally we don't control all the source (e.g. third-party libraries that define constants). We're interested in detecting these dependencies from the perspective of <strong>using</strong> the constants. Since the reference is erased from the code that <strong>uses</strong> the constants, there is no easy way to detect them, short of doing source code analysis.</p>