Effective Java 3rd Edition -- Creating and Destroying Objects

今天药忘吃喽~ 2022-05-29 07:40 229阅读 0赞

本章涉及创建和销毁对象:何时以及如何创建它们,何时以及如何避免创建它们,如何确保它们及时销毁,以及如何管理必须在销毁之前进行的清理操作。

  • Item 1: Consider static factory methods instead of constructors
  • Item 2: Consider a builder when faced with many constructor parameters
  • Item 3: Enforce the singleton property with a private constructor or an enum type
  • Item 4: Enforce noninstantiability with a private constructor
  • Item 5: Prefer dependency injection to hardwiring resources
  • Item 6: Avoid creating unnecessary objects
  • Item 7: Eliminate obsolete objects references
  • Item 8: Avoid finalizers and cleaners
  • Item 9: Prefer try-with-resources to try-finally

发表评论

表情:
评论列表 (有 0 条评论,229人围观)

还没有评论,来说两句吧...

相关阅读