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.

A+
Osvaldo

On Sunday, November 27, 2011 6:29:59 PM UTC-5, fabrizio.giudici wrote:
>
> On Sun, 27 Nov 2011 14:20:17 +0100, Ben Schulz <ya...@gmx.de> wrote:
>
> > As far as I am aware there is no (Java-standard-compliant) way to
> > change the value of static final fields (excepting of course the
> > previously noted System.in, out and err). And as far as the JVM is
> > concerned the same holds true for non-static final fields. Just
> > recently Cliff Click wrote two blog posts about that[1,2].
> >
> > With kind regards
> > Ben
> >
> > [1]:  
> > 
> http://www.azulsystems.com/blog/cliff/2011-10-17-writing-to-final-fields-via-reflection
> > [2]: 
> http://www.azulsystems.com/blog/cliff/2011-10-27-final-fields-part-2
>
> Some people argue the opposite:
>
>
> http://stackoverflow.com/questions/2474017/using-reflection-to-change-static-final-file-separatorchar-for-unit-testing
>
>
> Didn't find the time to try it, though.
>
>
> -- 
> Fabrizio Giudici - Java Architect, Project Manager
> Tidalwave s.a.s. - "We make Java work. Everywhere."
> fabrizio...@tidalwave.it
> http://tidalwave.it - http://fabriziogiudici.it
>
>

-- 
You received this message because you are subscribed to the Google Groups "The 
Java Posse" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/javaposse/-/LhzHHoGAqCkJ.
To post to this group, send email to javaposse@googlegroups.com.
To unsubscribe from this group, send email to 
javaposse+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/javaposse?hl=en.

Reply via email to