Effective Java 目录

《Effective Java》目录摘抄。
我知道这看起来很糟糕。当下,自己缺少实际操作,只能暂时摘抄下目录。随着,实践的增多,慢慢填充更多的示例。

Chapter 2 Creating and Destroying Objects

  • Consider static factory methods instead of constructors
  • Consider a builder when faced with many constructor parameters
  • Enforce the singleton property with a private constructor or an enum type
  • Avoid creating unnecessary objects
  • Eliminate obsolete object references
  • Avoid finalizers

Chapter 3 Methods Common to All Objects

  • Obey the general contract when overriding equals
  • Always override hashCode when you override equals
  • Always override toString
  • Override clone judiciously
  • Consider implementing Comparable

Chapter 4 Classes and Interfaces

  • Minimize the accessibility of classes and members
  • In public classes, use accessor methods, not public fields
  • Minimize mutability
  • Favor composition over inheritance
  • Design and document for inheritance or else prohibit it
  • Prefer interfaces to abstract classes
  • Use interfaces only to define types
  • Prefer class hierarchies to tagged classes
  • Use function objects to represent strategies
  • Favor static member classes over nonstatic

Chapter 5 Generics

  • Don't use raw types in new code
  • Eliminate unchecked warnings
  • Prefer lists to arrays
  • Favor generic types
  • Favor generic methods
  • Use bounded wildcards to increase API flexibility
  • Consider typesafe heterogeneous containers

Chapter 6 Enums and Annotations

  • Use enums instead of int costants
  • Use instance fields instead of ordinals
  • Use EnumSet instead of bit fields
  • Use EnumMap instead of ordinal indexing
  • Emulate extensible enums with interfaces
  • Prefer annotations to naming patterns
  • Consistently use the Override annotation
  • Use marker interfaces to define types

Chapter 7 Methods

  • Check parameters for validity
  • Make defensive copies when needed
  • Design method signatures carefully
  • Use overloading judiciously
  • Use varargs judiciously
  • Return empty arrays or collections, not nulls
  • Write doc comments for all exposed API elements

Chapter 8 General Programming

  • Minimize the scope of local variables
  • Prefer for-each loops to traditional for loops
  • Know and use the libraries
  • Avoid float and double if exact answers are required
  • Prefer primitive types to boxed primitives
  • Avoid strings where other types are more appropriate
  • Beware the performance of string concatenation
  • Refer to objects by their interfaces
  • Prefer interfaces to reflection
  • Use native methods judiciously
  • Optimize judiciously
  • Adhere to generally accepted naming conventions

Chapter 9 Exceptions

  • Use exceptions only for exceptional conditions
  • Use checked exceptions for recoverable conditions and runtime exceptions for programming errors
  • Avoid unnecessary use of checked exceptions
  • Favor the use of standard exceptions
  • Throw exceptions appropriate to the abstraction
  • Document all exceptions thrown by each method
  • Include failure-capture information in detail messages
  • Strive for failure atomicity
  • Don't ignore exceptions

Chapter 10 Concurrency

  • Synchronized access to shared mutable data
  • Avoid excessive synchronization
  • Prefer executors and tasks to threads
  • Prefer concurrency utilities to wait and notify
  • Document thread safety
  • Use lazy initialization judiciously
  • Don't depend on the thread scheduler
  • Avoid thread groups

Chapter 11 Serialization

  • Implement Serializable judiciously
  • Consider using a custom serialized form
  • Write readObject methods defensively
  • For instance control, prefer enum types to readResolve
  • Consider serialization proxies instead of serialized instances

转载于:https://www.cnblogs.com/linkworld/p/9535760.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值