Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Also, inlining of <code>public</code> constants may be a source of problems that are hard to target, since they don't cause exceptions or errors, but cause silent wrong behaviour.</p> <p>Lets say you have a class <strong>A</strong> with some <code>public static final</code> fields that are of a primitive type or a <code>String</code> and whose values can be determined at compile time.</p> <pre><code>public class A { public static final String GREETING = "Hello"; ... } </code></pre> <p>Then if another class <strong>B</strong> accesses this field, the compiler inlines the constant - i.e. replaces the <code>A.GREETING</code> reference with its value <code>"Hello"</code>. No information of where the constant value comes from is kept.</p> <p>Now comes the trouble - if you change the value of <code>GREETING</code> to lets say <code>"Hi"</code> and recompile only the class <strong>A</strong>, the inlined value in class <strong>B</strong> will remain unchanged until you recompile it too. Therefore, <strong>it is usually a better idea to rebuild the entire application from scratch</strong>, as others have already pointed out.</p> <p>A nice article discussing this problem: <a href="http://marxsoftware.blogspot.com/2009/09/inconstant-constants-in-java.html" rel="nofollow noreferrer">http://marxsoftware.blogspot.com/2009/09/inconstant-constants-in-java.html</a></p> <p>Some related SO questions:</p> <p><a href="https://stackoverflow.com/questions/1406616/is-java-guaranteed-to-inline-string-constants-if-they-can-be-determined-at-compi">Is Java guaranteed to inline string constants if they can be determined at compile time</a></p> <p><a href="https://stackoverflow.com/questions/377819/are-all-compile-time-constants-inlined">Are all compile-time constants inlined?</a></p>
    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.
    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