Re: strange behevior of the JVM or compiler...



On Sat, 7 Jul 2007 23:55:52 +0200, "Thomas" <arabel9@xxxxx> wrote,
quoted or indirectly quoted someone who said :

class dummy{
public final static long mod = (long)2 * 3 * 5;

}
and then from the second class I call :

System.out.println(dummy.mod);
and if I do try to change the value of ' mod ' in code by changing
initialization line I STILL GET THE OLD VALUE NO MATTER HOW MANY TIMES I DO
COMPILE AND RUN. Is it the bug in JVM or in my IDE ?
cm
I see two problems. First dummy should be Dummy. See
http://mindprod.com/jgloss/naming.html


Second, static finals get turned into literals (constants) even when
they are referred outside the class. If you modify them, you must
recompile the universe to make sure the new value gets propagated.

If you look inside the class file for your second class, you will see
code like this println(30) and you will see it has not been recompiled
since you changed the value of mod.

I discuss this is greater depth in
http://mindprod.com/jgloss/javacexe.html

The rule of thumb is, when every you change public statics, recompile
everything, deleting all class files before you start.

The other rule of thumb is, when you see anomalies, first try a global
clean compile before you waste too much time trying to chase it down.
--
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
.