Brian

20%
Flag icon
Note that a nonzero-length array is always mutable, so it is wrong for a class to have a public static final array field, or an accessor that returns such a field. If a class has such a field or accessor, clients will be able to modify the contents of the array. This is a frequent source of security holes:
Brian
Oops, have committed this error before. Use immutable Collections (some examples https://www.baeldung.com/java-immutable-list) instead?
Robert
· Flag
Robert
This is often used as a workaround. If you have an anonymous inner class that needs to modify a value — say, an int — of its enclosing method (but values accessed by an inner class must be final) a fr…
Effective Java
Rate this book
Clear rating
Open Preview