Dan Patsey wrote:
Larry Olson wrote:I know java allows final instance variables. But my question is what good is a final instance variable? If the value is final, it means all the objects of that class will have the same value for that instance variable. What purpose would it serve?
Why not replace it by a final static variable? Wouldn't it fit the requirement?
So why do we have a final instance variable in java?
An example from Spring:
If the above class variable was static instead of instance, the logger would reflect the wrong class in different subclasses. (I think it would be the first one that was instantiated.)
Larry Olson wrote:I know java allows final instance variables. But my question is what good is a final instance variable? If the value is final, it means all the objects of that class will have the same value for that instance variable. What purpose would it serve?
Why not replace it by a final static variable? Wouldn't it fit the requirement?
So why do we have a final instance variable in java?