Effective Java的笔记(93)

>我来写笔记

按有用程度 按页码先后 最新笔记

  • OrangeCLK

    OrangeCLK

    Here are some common names for static factory methods: - valueOf--Returns an instance that has, loosely speaking, the same value as its parameters. Such static factories are effectively type-conversion methods. - of--A concise alternative to valueOf, popularized by EnumSet. - getInstance--Returns an instance that is described by the parameters but cannot be said to have the same value. In...

    2016-07-15 11:19

  • OrangeCLK

    OrangeCLK

    To make a class immutable, follow these five rules: 1. Don't provide any methods that modify the object's state. 2. Ensure that the class can't be extended. 3. Make all filelds final. 4. Make all fields private. 5. Ensure exclusive access to any mutable components.

    2016-07-14 16:32

  • OrangeCLK

    OrangeCLK

    这一整章都很好,越看越清楚。 Builder 和 Design Pattern 的 Builder 不一样。

    2016-07-14 16:29

  • OrangeCLK

    OrangeCLK

    A safe, conservative policy is never to export two overloadings with the same number of parameters.

    2016-01-18 10:06

  • OrangeCLK

    OrangeCLK

    Prefer two-element enum types to boolean parameters.

    2016-01-18 01:50

  • OrangeCLK

    OrangeCLK

    It is essential to make a defensive copy of each mutable parameter to the constructor 应该是个挺显然的事情。但我以前从未想到过。引用传递破坏了权限控制关键字的作用,这算是设计缺陷吧。

    2016-01-17 21:21

  • OrangeCLK

    OrangeCLK

    The Enum specification has this to say about ordinal: "Most programmers will have no use for this method. It is designed for use by general-purpose enum-based data structures such as EnumSet and EnumMap." Unless you are writing such a data structure, you are best off avoiding the ordinal method entirely.

    2016-01-14 21:40

  • OrangeCLK

    OrangeCLK

    Nulling out object references should be the exception rather than the norm. The best way to eliminate an obsolete reference is to let the variable that contained the reference fall out of scope. This occurs naturally if you define each variable in the narrowest possible scope.

    2016-01-13 16:49

  • OrangeCLK

    OrangeCLK

    a single-element enum type is the best way to implement a singleton.

    2016-01-13 16:03

  • seahawk

    seahawk

    本节虽短,收获却比前两节多。serialization和reflection的问题没有想到过。用enum实现singleton的方法也是第一次见。

    2015-11-08 13:46

<前页 1 2 3 4 5 6 7 8 9 10 后页>

笔记是你写在书页留白边上的内容;是你阅读中的批注、摘抄及随感。

笔记必须是自己所写,不欢迎转载。摘抄原文的部分应该进行特殊标明。

Effective Java

>Effective Java