Skip to main content
10 events
when toggle format what by license comment
Oct 15, 2013 at 15:16 comment added ftr let us continue this discussion in chat
Oct 15, 2013 at 13:38 comment added nablex This is rather pointless. You know very well that any external call to a private class variable is going to go through the getter hence the finality is wasted if you don't secure the getter, especially considering that the topic at hand is immutability.
Oct 15, 2013 at 12:33 comment added ftr I disagree. The private variable value is guaranteed to be immutable if it is final. If you override the getter in a subclass with some other value, that may be a problem, but does have no bearing on the state of the field itself.
Oct 15, 2013 at 12:17 comment added nablex The immutability of the private variable "value" is wasted without protecting the getter.
Oct 15, 2013 at 12:07 comment added ftr The getter has nothing to do with the immutability of value, though. But if you want to make value immutable and prohibit overriding of the getter, you can just make both the field and the getter final. Overriding a getter of an immutable field has a smelly feeling to it anyway.
Oct 15, 2013 at 12:00 comment added nablex Making a field final is not good enough if the getter isn't final. A child class can simply override the getter and use some other mutable value
Oct 15, 2013 at 11:53 comment added ftr Well, if field immutability is the goal, making the fields final is the way to go.
Oct 15, 2013 at 11:52 history edited ftr CC BY-SA 3.0
added 91 characters in body
Oct 15, 2013 at 11:47 comment added nablex I meant to say that the argument is used that the entire class is final because its fields have to be immutable, not that the class itself is "immutable" as it of course refers to its fields.
Oct 15, 2013 at 11:44 history answered ftr CC BY-SA 3.0