Skip to content

Commit

Permalink
Fixed double check idiom example from page 334 as was done in the thi…
Browse files Browse the repository at this point in the history
  • Loading branch information
jbloch committed Sep 12, 2019
1 parent 9e91e8a commit bdc828a
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/effectivejava/chapter11/item83/Initialization.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ private static class FieldHolder {
// 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)
Expand All @@ -38,6 +39,7 @@ private FieldType getField4() {
}



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

Expand Down

1 comment on commit bdc828a

@A-Lyon
Copy link

@A-Lyon A-Lyon commented on bdc828a Jan 25, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

omg you dirty man!

Please sign in to comment.