Re: strange behevior of the JVM or compiler...
- From: Roedy Green <see_website@xxxxxxxxxxxxxxxxxxxx>
- Date: Sun, 08 Jul 2007 16:33:45 GMT
On Sat, 7 Jul 2007 23:55:52 +0200, "Thomas" <arabel9@xxxxx> wrote,
quoted or indirectly quoted someone who said :
class dummy{cm
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 ?
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
.
- Follow-Ups:
- Re: strange behevior of the JVM or compiler...
- From: Twisted
- Re: strange behevior of the JVM or compiler...
- References:
- strange behevior of the JVM or compiler...
- From: Thomas
- strange behevior of the JVM or compiler...
- Prev by Date: Re: Java Time Discrepancy
- Next by Date: Re: Lists of size Integer.MAX_VALUE
- Previous by thread: strange behevior of the JVM or compiler...
- Next by thread: Re: strange behevior of the JVM or compiler...
- Index(es):