Robert

78%
Flag icon
In the presence of multiple threads, lazy initialization is tricky. If two or more threads share a lazily initialized field, it is critical that some form of synchronization be employed, or severe bugs can result (Item 78).
Robert
A bit more specificity would be helpful here. I think it's safe to say that the initialization of the field is often idempotent (i.e., the extra initialization shouldn't have side effects other than inefficient), and redundant initialization should only be a problem if the it's creating objects that depend on a mutuable shared, non-thread-safe fields (should be rare as well as bad). Edit: this case is mentioned as acceptable later.
Effective Java
Rate this book
Clear rating
Open Preview