摘要: Chapter 11 Serialization Item 74: Implement Serializable judiciously 让一个类的实例可以被序列化不仅仅是在类的声明中加上“implements Serializable”那么简单。 当你的类implements Serializab 阅读全文
posted @ 2017-07-30 10:06 raytheweak 阅读(213) 评论(0) 推荐(0) 编辑
摘要: Chapter 10 Concurrency Item 66: Synchronize access to shared mutable data synchronized这个关键字不仅保证了同步,还保证了可见性(visibility)。 对于变量的读写是原子性的,除非变量类型是long或doubl 阅读全文
posted @ 2017-07-28 23:14 raytheweak 阅读(274) 评论(0) 推荐(0) 编辑
摘要: Chapter 9 Exceptions Item 57: Use exceptions only for exceptional conditions 这条item的意思就是,千万不要用exception来控制control flow的终止,比如: 这段代码用异常来终止循环,这根本就不是异常的归宿 阅读全文
posted @ 2017-07-23 15:00 raytheweak 阅读(270) 评论(0) 推荐(0) 编辑
摘要: Chapter 8 General Programming Item 45: Minimize the scope of local variables local variables应该在他们要被用的地方声明,而不应该,比如,全部声明在方法开头。而且在声明的时候,记得要初始化。有个例外,比如你的 阅读全文
posted @ 2017-07-23 14:46 raytheweak 阅读(172) 评论(0) 推荐(0) 编辑
摘要: Chapter 7 Methods Item 38: Check parameters for validity 直接举例吧: java / ...其他的被我省略了 @throws ArithmeticException if m is less than or equal to 0 / publi 阅读全文
posted @ 2017-07-23 13:40 raytheweak 阅读(257) 评论(0) 推荐(0) 编辑
摘要: Chapter 6 Enums and Annotations Item 30: Use enums instead of int constants Enum类型无非也是个普通的class,所以你可以给他加class能有的东西,比如constructor: 我记得我在thinking in jav 阅读全文
posted @ 2017-07-18 20:13 raytheweak 阅读(245) 评论(0) 推荐(0) 编辑
摘要: Chapter 5 Generics Item 23: Don’t use raw types in new code 虽然你可以把一个 传给一个List类型(raw type)的参数,但你不应该这么做(因为允许这样只是为了兼容遗留代码),举个例子: 以上代码说明如果你把 类型转换成List类型,就 阅读全文
posted @ 2017-07-16 12:15 raytheweak 阅读(246) 评论(0) 推荐(0) 编辑
摘要: Chapter 4 Classes and Interfaces Item 13: Minimize the accessibility of classes and members 一个好的模块设计会封装所有实现细节,模块之间只能通过他们公开的API进行交流。因为这些模块互不影响(loosely 阅读全文
posted @ 2017-07-16 11:17 raytheweak 阅读(287) 评论(0) 推荐(0) 编辑
摘要: Chapter 3 Methods Common to All Objects Item 8: Obey the general contract when overriding equals 以下几种情况不需要你override这个类的equals方法:这个类的每一个实例天生就是unique的,比 阅读全文
posted @ 2017-07-15 11:00 raytheweak 阅读(208) 评论(0) 推荐(0) 编辑
摘要: Chapter 2 Creating and Destroying Objects item 1:Consider static factory methods instead of constructors 一个static factory method只不过是一个返回这个类的实例的static方 阅读全文
posted @ 2017-07-15 10:23 raytheweak 阅读(238) 评论(0) 推荐(0) 编辑