《Effective Java(影印版) (平装)》的原文摘录

  • 大多数程序员都不需要这个方法(指枚举的ordinal方法),他是设计成用于像EnumSet和EnumMap这种基于枚举的通用数据结构的,除非你在编写的是这类数据结构,否则最好完全避免使用ordinal方法。 (查看原文)
    laichendong 2012-01-05 21:48:55
    —— 引自第137页
  • 如果类具有从客户端得到或返回到客户端的可变组件。类就必须保护性的拷贝这些组件。如果拷贝的成本受到限制,并且信任他的客户端不会不恰当的修改组件,就可以在文档中指明客户端的职责是不得修改受到影响的组件,以此来代替保护性拷贝 (查看原文)
    laichendong 2012-01-09 16:36:09
    —— 引自第159页
  • 谨慎地选择方法的名称 (查看原文)
    laichendong 2012-01-10 16:12:29
    —— 引自第163页
  • 不要过于追求提供便利的方法 (查看原文)
    laichendong 2012-01-10 16:12:29
    —— 引自第163页
  • 避免过长的参数列表 (查看原文)
    laichendong 2012-01-10 16:12:29
    —— 引自第163页
  • 要调用哪个重载(overloading)方法是在编译期做出决定的 重载方法(overloaded method)的选择是静态的,而对于被覆盖的方法(overridden method)的选择则是动态的 (查看原文)
    laichendong 2012-01-12 10:56:29
    —— 引自第165页
  • “能够重载方法”并不意味着就“应该重载方法”。一般情况下,对于多个具有相同参数数目的方法来说。应该尽量避免重载方法。 (查看原文)
    laichendong 2012-01-12 10:56:29
    —— 引自第165页
  • 返回长度为0的数组或集合,而不是null。 (查看原文)
    laichendong 2012-01-17 10:58:10
    —— 引自第174页
  • It is critical to check the validity of constructor parameters to prevent the construction of an object that violates its class invariants. (查看原文)
    小鲁 1赞 2012-01-20 22:59:23
    —— 引自第206页
  • do not use the clone method to make a defensive copy of a parameter whose type is subclassable by untrusted parties. (查看原文)
    小鲁 2012-01-20 23:13:55
    —— 引自第209页
  • Item 57: Use exceptions only for exceptional conditions Item 58: Use checked exceptions for recoverable conditions and runtime exceptions for programming errors Item 59: Avoid unnecessary use of checked exceptions Item 60: Favor the use of standard exceptions Item 61: Throw exceptions appropriate to the abstraction Item 62: Document all exceptions thrown by each method Item 63: Include failure-capture information in detail messages Item 64: Strive for failure atomicity Item 65: Don’t ignore exceptions (查看原文)
    skeeey 1回复 2013-09-30 15:50:50
    —— 引自第241页
  • Errors are reserved for use by the JVM to indicate resource defi-ciencies, invariant failures, or other conditions that make it impossible to continue execution (查看原文)
    skeeey 1回复 2013-09-30 15:50:50
    —— 引自第241页
  • 数组与泛型相比,有两个重要的不同点。首先,数组是协变的(covariant)。...相反,泛型则是不可变的(invariant)。...利用数组,你会在运行时发现所犯的错误;利用列表,则可以在编译时发现错误。...第二大区别在于,数组是具体化的(feified)。相比之下,泛型则是通过擦除来实现的 (查看原文)
    长脸方 2013-11-18 09:32:21
    —— 引自章节:泛型
  • 工具类(utility class)不希望被实例化,实例对它没有任何意义 (查看原文)
    长脸方 2013-11-26 20:17:10
    —— 引自章节:创建和销毁对象
  • prefer primitives to boxed primitives, and watch out for unintentional autoboxing. (查看原文)
    OrangeCLK 2014-04-23 21:46:29
    —— 引自第23页
  • 使公有的类型成为可变的,这可能会导致大量不必要的保护性拷贝。 (查看原文)
    红色有角F叔 2014-05-03 10:55:00
    —— 引自章节:谨慎地做优化
  • 要努力编写好的程序而不是快的程序 (查看原文)
    DaR.K 2015-03-13 17:33:36
    —— 引自第205页
  • a single-element enum type is the best way to implement a singleton. (查看原文)
    OrangeCLK 2016-01-13 16:03:03
    —— 引自第18页
  • 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. (查看原文)
    OrangeCLK 2016-01-13 16:49:32
    —— 引自第25页
  • 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. (查看原文)
    OrangeCLK 2016-01-14 21:40:12
    —— 引自第158页
<前页 1 2 3 后页>