Skip to content

Commit bdc828a

Browse files
committed
Fixed double check idiom example from page 334 as was done in the third printing.
See errata page for details: https://docs.google.com/document/d/1mAeEgQu4H4ADxa03k7YaVDjIP5vJBvjVIjg3DIvoc8E/
1 parent 9e91e8a commit bdc828a

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

src/effectivejava/chapter11/item83/Initialization.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ private static class FieldHolder {
2525
// Double-check idiom for lazy initialization of instance fields - Page 334
2626
private volatile FieldType field4;
2727

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

4041

42+
4143
// Single-check idiom - can cause repeated initialization! - Page 334
4244
private volatile FieldType field5;
4345

0 commit comments

Comments
 (0)