Originally posted by Ernest Friedman-Hill:
The variable here isn't final, it's static, and if you mark it "final" instead it won't compile.
That was stupid of me... I really didn't expect to be able to use the initializer block but didn't second guess when it worked...
Originally posted by Ernest Friedman-Hill:
But I know what you're saying. I think it's possible to get some version of this idea to run (inspecting a final variable before it's set), but off the top of my head I don't remember how. Even without that trick, it's possible to use reflection to change the value of a final variable, showing that they're really not "immutable" at all.
Right, I just wanted to show that the variable exists, has an initial value of null, and that initial value is changed with the assignment. I was hoping it would be easy to show but now I think you have to resort to Reflection trickery to get around the compile errors.
[ July 28, 2008: Message edited by: Steve Luke ]