The guidelines in this chapter address areas where developers often make unwarranted assumptions about Java language and library behaviors, or where ambiguities can easily be introduced. Failure to follow these guidelines can result in programs that produce counterintuitive results.

This chapter contains guidelines that address

  1. Misconceptions about Java APIs and language features
  2. Assumptions and ambiguity-laced programs
  3. Situations in which the programmer wanted to do one thing but ended up doing another

 

66. Do not assume that declaring a reference volatile guarantees safe publication of the members of the referenced object
67. Do not assume that the sleep(), yield(), or getState() methods provide synchronization semantics
68. Do not assume that the remainder operator always returns a nonnegative result for integral operands
69. Do not confuse abstract object equality with reference equality
70. Understand the differences between bitwise and logical operators
71. Understand how escape characters are interpreted when strings are loaded
72. Do not use overloaded methods to differentiate between runtime types
73. Never confuse the immutability of a reference with that of the referenced object
74. Use the serialization methods writeUnshared() and readUnshared() with care
75. Do not attempt to help the garbage collector by setting local reference variables to null