最近每天上班下班有点时间看下 Effective Java。
我一般看看原文,在看看示例代码,再想想原文的意思。
我英文也不是很好,所以决定中文英文随便用.
Creating and destroying objects
Item 1: Consider static factory methods instead of constructors
Advantage of static factory methods |
1.Unlike constructors. They have names. |
2.They are not required to create a new object each time they’re invoked. |
3.They can return an object of any subtype of their return type. |
4.They reduce the verbosity of creating parameterized type instances. |
1.
public static Boolean valueOf(boolean b){ return b?Boolean.TRUE:Boolean.FALSE; }
3.
A service provider framework.
In the case of JDBC . Connection plays the part of the service interface,DriverManager.registerDriver is the provider registration API,DriverManager.getConnection is the service access API,and Driver is the service provider interface.
时间: 2024-10-12 20:22:07