A Zen gay atheistic Texan’s perspective

For you Java geeks out there. Did you know this one?

If Class A references a static final String in Class B (a “constant”), and you change the value of the constant in Class B and recompile, will Class A reference the old or new value?

And the answer is….the old value!! Java embeds the String literal in Class A rather than a reference to Class B (which is what I think it should do, then put a reference to the literal in B). So, you have to recompile everything when you change constants. What fun!!!!

The lesson? Don’t change the value of constants.

September 8th, 2005 at 5:45 pm