Giselle,
Let look at Corey's code with line numbers:
The trick to Corey's code is his use of a
instance initializer on lines 4,5,6.
So Im coming to the conclusion that final variables do get assigned default values but the compiler do not accept them so you have to make an explicit assignment in order for it to compile and after that, you can even use the default values assigned?
To answer your question:
I don't believe a "blank final variable" can ever use the default value, except in the context of the instance initializer. So if you use instance initializers--or static initializers; yes, such a beast exists too--you can use the default value, but in practice, instance initializers are fairly rare. They were introduced to support anonymous inner classes.
Basically, when you comment out line 12 you're
violating the caveat that the final variable must be explicitly assigned a value before any constructor completes. When the program enters the main method a call to the constructor is made, and the compiler wants to know that your going to feed it a final variable that has been "fattened for the kill." Otherwise the variable holds nothing but empty calories and the compiler is going to complain about not getting enough to eat!
PS... You can also have static initializers. But in the context of the example...
A class can have any number of static or instance initializers. A static initializer is like a class, or static, method. It has no access to instance variables or methods. As the keyword static would suggest.
[ May 12, 2003: Message edited by: Timothy Stone ]