On Sat, 03 Dec 2011 02:03:12 +0100, opinali <[email protected]> wrote:

Even if this works, be warned that static final fields are special in that
the JVM is allowed to make static constant-propagation optimization, at
least for fields of primitive types, without any guard code. So if you have some code like "if (DEBUG) {...}" and DEBUG==false at the time this code is
first executed, the VM will obliterate that code to nothingness - this is
guaranteed by spec, it's the only way to obtain conditional compilation in Java. (I think even the interpreter will do this, no need to wait for JIT.)
Even if afterwards you change DEBUG to true (JNI will certainly work as a
last resort), that CSE-optimized code will *not* be recompiled to be
consistent with the new value.

The discussion about reflection and constants was merely academical. Of course changing constants by reflection is bad idea for any practical purpose.


--
Fabrizio Giudici - Java Architect, Project Manager
Tidalwave s.a.s. - "We make Java work. Everywhere."
[email protected]
http://tidalwave.it - http://fabriziogiudici.it

--
You received this message because you are subscribed to the Google Groups "The Java 
Posse" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/javaposse?hl=en.

Reply via email to