Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If the value assigned to a <code>static final boolean</code> field is known at compile-time, it is a <em>constant.</em> Fields of primitive or <code>String</code> type can be compile-time constants. A constant will be inlined in any code that references the field. Since the field is not actually read at runtime, changing it then will have no effect.</p> <p>The <a href="https://docs.oracle.com/javase/specs/jls/se10/html/jls-13.html#jls-13.4.9" rel="nofollow noreferrer">Java language specification</a> says this:</p> <blockquote> <p>If a field is a constant variable (§4.12.4), then deleting the keyword final or changing its value will not break compatibility with pre-existing binaries by causing them not to run, but <strong>they will not see any new value for the usage of the field unless they are recompiled.</strong> This is true even if the usage itself is not a compile-time constant expression (§15.28)</p> </blockquote> <p>Here's an example:</p> <pre><code>class Flag { static final boolean FLAG = true; } class Checker { public static void main(String... argv) { System.out.println(Flag.FLAG); } } </code></pre> <p>If you decompile <code>Checker</code>, you'll see that instead of referencing <code>Flag.FLAG</code>, the code simply pushes a value of 1 (<code>true</code>) onto the stack (instruction #3).</p> <pre><code>0: getstatic #2; //Field java/lang/System.out:Ljava/io/PrintStream; 3: iconst_1 4: invokevirtual #3; //Method java/io/PrintStream.println:(Z)V 7: return </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload