Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You can't change a <code>final</code> variable. That's what makes it <code>final</code>. But there is nothing wrong with passing the <code>final</code> variable to a function. In fact, the sample code that you posted runs just fine.</p> <p>In your list of steps, you said 'change DATA to "B"' though your code doesn't show this step. But that's fine, since that step wouldn't compile.</p> <p>If you need to alter a <code>final</code> variable before passing it to a function, you need to make a local copy and change that copy instead.</p> <p><strong>Update:</strong> Now that the question has been clarified, here are some more thoughts:</p> <p>It sounds like something isn't being recompiled properly. Perhaps you are running from an old version of the classes (i.e. you need to copy it somewhere)?</p> <p>Also, you should know that although you may change the <code>TestData</code> class, because <code>DATA</code> is declared <code>static final</code>, Java may have inlined that constant into the <code>MyTest</code> class (since it is guaranteed to never change) so you need to make sure that <code>MyTest</code> is also recompiled.</p> <p>If you want to verify that you are using the latest version of a class, put some very "loud" code in a place where you know it should execute. For example, a <code>System.out.println</code> or even throw a <code>RuntimeException</code> (sure, your program will fail, but if it doesn't fail then you <em>know</em> that something isn't being recompiled properly which will help you diagnose what is wrong).</p>
 

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