Skip to content
Permalink
Browse files

Fixed double check idiom example from page 334 as was done in the thi…

  • Loading branch information...
jbloch committed Sep 12, 2019
1 parent 9e91e8a commit bdc828a7af2bdfac28e3c38bd7d1a2ae05736ccc
Showing with 2 additions and 0 deletions.
  1. +2 −0 src/effectivejava/chapter11/item83/Initialization.java
@@ -25,6 +25,7 @@ private synchronized FieldType getField2() {
// Double-check idiom for lazy initialization of instance fields - Page 334
private volatile FieldType field4;

// NOTE: The code for this method in the first printing had a serious error (see errata for details)!
private FieldType getField4() {
FieldType result = field4;
if (result != null) // First check (no locking)
@@ -38,6 +39,7 @@ private FieldType getField4() {
}



// Single-check idiom - can cause repeated initialization! - Page 334
private volatile FieldType field5;

0 comments on commit bdc828a

Please sign in to comment.
You can’t perform that action at this time.