1 introduction 1 \n2 creating and destroying objects 5 \nitem 1: consider static factory methods instead of constructors 5 \nitem 2: consider a builder when faced with many constructor parameters 11 \nitem 3: enforce the singleton property with a private constructor or an enum type 17 \nitem 4: enforce noninstantiability with a private constructor 19 \nitem 5: avoid creating unnecessary objects 20 \nitem 6: eliminate obsolete object references 24 \nitem 7: avoid finalizers 27 \n3 methods common to all objects 33 \nitem 8: obey the general contract when overriding equals 33 \nitem 9: always override hashcode when you overrideequals 45 \nitem 10: always override tostring 51 \nitem 11: override clone judiciously 54 \nitem 12: consider implementing comparable 62 \n4 classes and interfaces 67 \nitem 13: minimize the accessibility of classes and members 67 \nitem 14: in public classes, use accessor methods, not public fields 71 \nitem 15: minimize mutability 73 \nitem 16: favor composition over inheritance 81 \nitem 17: design and document for inheritance or else prohibit it 87 \nitem 18: prefer interfaces to abstract classes 93 \nitem 19: use interfaces only to define types 98 \nitem 20: prefer class hierarchies to tagged classes 100 \nitem 21: use function objects to represent strategies 103 \nitem 22: favor static member classes over nonstatic 106 \n5 generics 109 \nitem 23: don't use raw types in new code 109 \nitem 24: eliminate unchecked warnings 116 \nitem 25: prefer lists to arrays 119 \nitem 26: favor generic types 124 \nitem 27: favor generic methods 129 \nitem 28: use bounded wildcards to increase api flexibility 134 \nitem 29: consider typesafe heterogeneous containers 142 \n6 enums and annotations 147 \nitem 30: use enums instead of int constants 147 \nitem 31: use instance fields instead of ordinals 158 \nitem 32: use enumset instead of bit fields 159 \nitem 33: use enummap instead of ordinal indexing 161 \nitem 34: emulate extensible enums with interfaces 165 \nitem 35: prefer annotations to naming patterns 169 \nitem 36: consistently use the override annotation 176 \nitem 37: use marker interfaces to define types 179 \n7 methods 181 \nitem 38: check parameters for validity .. 181 \nitem 39: make defensive copies when needed 184 \nitem 40: design method signatures carefully 189 \nitem 41: use overloading judiciously 191 \nitem 42: use varargs judiciously 197 \nitem 43: return empty arrays or collections, not nulls 201 \nitem 44: write doc comments for all exposed api elements 203 \n8 general programming 209 \nitem 45: minimize the scope of local variables 209 \nitem 46: prefer for-each loops to traditional for loops 212 \nitem 47: know and use the libraries 215 \nitem 48: avoid float and double if exact answers are required 218 \nitem 49: prefer primitive types to boxed primitives 221 \nitem 50: avoid strings where other types are more appropriate 224 \nitem 51: beware the performance of string concatenation 227 \nitem 52: refer to objects by their interfaces 228 \nitem 53: prefer interfaces to reflection 230 \nitem 54: use native methods judiciously 233 \nitem 55: optimize judiciously 234 \nitem 56: adhere to generally accepted naming conventions 237 \n9 exceptions 241 \nitem 57: use exceptions only for exceptional conditions 241 \nitem 58: use checked exceptions for recoverable conditions and runtime exceptions for programming errors 244 \nitem 59: avoid unnecessary use of checked exceptions 246 \nitem 60: favor the use of standard exceptions 248 \nitem 61: throw exceptions appropriate to the abstraction 250 \nitem 62: document all exceptions thrown by each method 252 \nitem 63: include failure-capture information in detail messages 254 \nitem 64: strive for failure atomicity 256 \nitem 65: don't ignore exceptions 258 \n10 concurrency 259 \nitem 66: synchronize access to shared mutable data 259 \nitem 67: avoid excessive synchronization 265 \nitem 68: prefer executors and tasks to threads 271 \nitem 69: prefer concurrency utilities to wait and notify 273 \nitem 70: document thread safety 278 \nitem 71: use lazy initialization judiciously 282 \nitem 72: don't depend on the thread scheduler 286 \nitem 73: avoid thread groups 288 \n11 serialization 289 \nitem 74: implement serializable judiciously 289 \nitem 75: consider using a custom serialized form 295 \nitem 76: write readobject methods defensively 302 \nitem 77: for instance control, prefer enum types toreadresolve 308 \nitem 78: consider serialization proxies instead of serialized instances 312 \nappendix: items corresponding to first edition 317 \nreferences 321 \nindex 327
以下为对购买帮助不大的评价