|
ERRATA Effective Java Programming Language Guide by Joshua Bloch Foreword by Guy Steele |
|
This page contains the errata - those things that are wrong or lead you astray in the first edition of the book. The parenthesized number on the first line of each entry on this page represents the printing in which the erratum was fixed.
If you find an error in the book, please check to see if it is already known before reporting it. If you do not find it in the list, please mail me the relevant information, including page numbers. All errata will be fixed in the next possible printing.
The list of reviewers contains an omission:I am extremely grateful to David Holmes for all of his contributions and deeply sorry for this omission.
The sentence "The examples have been tested on releases 1.3." should be:The examples have been tested on release 1.3.
The reference to Design Patterns by Gamma, Helm, Johnson and Vlissides has the wrong year. Instead of [Gamma98], it should be:[Gamma95]
The first sentence of the third paragraph is imprecise. The word "immutable" shold be replaced by the phrase:not modified after initialization
The reference to Item 32 should be a reference to Item 24. It should read:The present item says: "Don't create a new object when you should reuse an existing one," while Item 24 says: "Don't reuse an existing object when you should create a new one."
When discussing the code example on page 17, the phrase "the items array" occurs twice. The array name in the prose does not match the one in the code. The phrase should be:the elements array
The sentence that ends "the finalizer guardian becomes eligible for finalization immediately prior to the enclosing instance" should end:the finalizer guardian becomes eligible for finalization at the same time as the enclosing instance.
The sentence that begins "Let's suppose that we have one case-sensitive string" should begin:Let's suppose that we have one case-insensitive string
In the sentence that begins, "The TimeStamp class is an anomaly," TimeStamp should be:Timestamp
The comment for the toString method exchanges the terms extension and exchange. It should read:* The string consists of fourteen characters whose format * is "(XXX) YYY-ZZZZ", where XXX is the area code, YYY is * the exchange, and ZZZZ is the extension ... * For example, if the value of the extension is 123, the last * four characters of the string representation will be "0123".
The last precondition in the comment of the toPaddedString method at the top of the page is incorrect."Integer.toString(i) <= length" should be:Integer.toString(i).length() <= length
The fifth line of the fourth paragraph is missing a period. The portion that reads, "of the original object The fields" should read:of the original object. The fields
clone judiciously (4)
In the sentence, "You will quickly find that your program produces nonsensical results or throwsArrayIndexOutOfBounds."ArrayIndexOutOfBoundsshould beNullPointerException:You will quickly find that your program produces nonsensical results or throws aNullPointerException.
clone judiciously (2)
The sentence that begins, "Note that this solution would not work if the buckets field were final" should begin:Note that this solution would not work if the elements field were final
clone Judiciously (5)
The if statement in the corrected clone method contains an unnecessary (though harmless) cast. It should read:if (buckets[i] != null) result.buckets[i] = buckets[i].deepCopy();
Comparable (2)
The sentence that begins "For example, consider theFloatclass" should begin:For example, consider theBigDecimalclass
All occurrences ofFloatin this paragraph should be:BigDecimal
The instance creation expressionnew Float(-0.0f)should be:new BigDecimal("1.0")
The instance creation expressionnew Float(0.0f)should be:new BigDecimal("1.00")
Comparable (5)
The sentence that ends "less than or equal to INTEGER.MAX_VALUE (231-1)." should end:less than or equal to Integer.MAX_VALUE (231-1).
The equals method contains this return statement:The final line is missing the characters "c." after the open parenthesis; the return statement should be:return (Float.floatToIntBits(re) == // See page 33 to Float.floatToIntBits(c.re))&& // find out why (Float.floatToIntBits(im) == // floatToIntBits Float.floatToIntBits(im)); // is used.return (Float.floatToIntBits(re) == // See page 33 to Float.floatToIntBits(c.re))&& // find out why (Float.floatToIntBits(im) == // floatToIntBits Float.floatToIntBits(c.im)); // is used.
The beginning of the sentence "An immutable object can provide static factories that cache" should be:An immutable class can provide static factories that cache
The class Complex has a private constructor but is supposed to be extensible from inside its package. For this the constructor needs to be package-private. The line that reads:should read:private Complex(float re, float im) {Complex(float re, float im) {
In the example code that begins:the result variable should be of type Foo. Also, the method fooVal is erroneously invoked as fooValue(). The example should read:// Cached, lazily initialized function of an immutable object private volatile Foo cachedFooVal = UNLIKELY_FOO_VALUE; public Foo foo() { int result = cachedFooVal;// Cached, lazily initialized function of an immutable object private volatile Foo cachedFooVal = UNLIKELY_FOO_VALUE; public Foo foo() { Foo result = cachedFooVal; if (result == UNLIKELY_FOO_VALUE) result = cachedFooVal = fooVal();
The sentence that begins, "If you've given the subclass a method with exactly the same signature" is imprecise. It should read:If you've given the subclass a method with the same signature and return type
The phrase, "before the subclass's clone methods has a chance" should read:before the subclass's clone method has a chance
On the bottom of the page the name of the method Sing is incorrectly capitalized. It should be:sing
On the bottom of the page comment above the hashCode method incorrectly capitalizes hashCode. The comment should read:// Implements the general contract of Map.Entry.hashCode
In the sentence that begins, "There are several constant interfaces in the java platform libraries," java should be capitalized:There are several constant interfaces in the Java platform libraries
The beginning of the sentence, "A nested classes should exist" should be:A nested class should exist
The two sentences, "Within instance methods of a nonstatic member class, it is possible to invoke methods on the enclosing instance. Given a reference to an instance of a nonstatic member class, it is possible to obtain a reference to the enclosing instance." should be replaced by the single sentence:Within instance methods of a nonstatic member class, it is possible to invoke methods on the enclosing instance, or to obtain a reference to the enclosing instance using the qualifiedthisconstruct [JLS, 15.8.4].
enum constructs with classes (5)
In the code example, the Operation constants PLUS, MINUS, TIMES and DIVIDE should be declared final:This was a moderately serious typo. In the absence of the final modifier, a malicious or careless client could wreak havoc by changing the values of the enum constants.public static final Operation PLUS ... public static final Operation MINUS ... public static final Operation TIMES ... public static final Operation DIVIDE ...
The sentence that ends, "because they're amenable to automatic method dispatching by the JVM, as in the Operator example." should end:because they're amenable to automatic method dispatching by the JVM, as in the Operation example.
The sentence that ends, "this problem in unlikely to be noticeable in practice." should end:this problem is unlikely to be noticeable in practice.
The sentence that begins "With the introduction of the Comparable interface, all of the these classes" should begin:With the introduction of the Comparable interface, all of these classes
The sentence that referred to Doclint was changed because the URL for the utility is no longer active. The sentence now reads:Also, there are utilities to check adherence to these rules [DocCheck].
The sentence that referred to the weblint utility was changed because the URL that once referred to the utility is now a disruptive page of advertising. The sentence now reads:Several HTML validity checkers are available for download.
The sentence "The framework is based on six collection interfaces (Collection, Set, List, Map, SortedList, and SortedMap)." contains "SortedList" in place of "SortedSet." The sentence should read:The framework is based on six collection interfaces (Collection, Set, List, Map, SortedSet, and SortedMap).
float and double if
exact answers are required (2)
Missing apostrophe: "its slower" should be:it's slower
The reference to java.util.ThreadLocal should be:java.lang.ThreadLocal
The line, "s.addAll(Arrays.asList(args).subList(1, args.length-1);" should read:s.addAll(Arrays.asList(args).subList(1, args.length);
In the sentence, "It has no benefits over an ordinary checked exceptionality would serve merely to confuse the user of your API." exceptionality should be "exception and":It has no benefits over an ordinary checked exception and would serve merely to confuse the user of your API.
The sentence that begins "While these are by far are the most commonly reused exceptions" should be:While these are by far the most commonly reused exceptions
The phrase "an example of exception transaction" should be:an example of exception translation
The statement, "In general, the double-check idiom does not work, although it does work if the shared variable contains a primitive value rather than an object reference [Pugh01b]." is too general. It should read:In general, the double-check idiom does not work, although it does work if the shared variable contains a primitive value other than alongordouble[Pugh01b].
wait outside a loop (4)
The reference in the phrase "(as in the WorkQueue example, Item 50)" should be:(as in the WorkQueue example, Item 49)
wait outside a loop (5)
Technically, a series does not have a sum; it is a sequence of sums. Therefore, the sentence "The sum of this series is O(n2)." should read:"This series is O(n2)."
wait outside a loop (5)
The reference to Lea99 is incorrect. The reference and surrounding text should read:Specific Notification [Cargill96, Lea00].
The local variable size in the readObject method should be renamed to avoid shadowing the size field in StringList. This is not a bug, but shadowing should be avoided on general principle, as it tends to be confusing. Instead of size the variable should be named:numElements
The Doclint URL is no longer functional, and has been replaced with a reference to Doc Check. (At the time of publication, Doc Check had not yet been released.) The reference is now:[DocCheck] Doc Check. Sun Microsystems. October 2001.
< http://java.sun.com/j2se/javadoc/doccheck/index.html>.
The weblint URL is now a disruptive page of advertising. The reference has been removed.