Joe Soltzberg

20%
Flag icon
You can expose constants via public static final fields, assuming the constants form an integral part of the abstraction provided by the class. By convention, such fields have names consisting of capital letters, with words separated by underscores (Item 68). It is critical that these fields contain either primitive values or references to immutable objects (Item 17). a field containing a reference to a mutable object has all the disadvantages of a nonfinal field. While the reference cannot be modified, the referenced object can be modified—with disastrous results.
Joe Soltzberg
It would be nice if this was its own, independent language feature
Brian
· Flag
Brian
to make an object immutable by type declaration? must be built into the class itself, but perhaps there could be a base type that did this pretty easily by making the core data private and unreachable…
Joe Soltzberg
· Flag
Joe Soltzberg
Oh, I actually was just referring to exposing constants via public static final fields and making that a bit less verbose

It would be nice if code was 'String constant VAR = "something"' instead of alw…
Effective Java
Rate this book
Clear rating
Open Preview