一个final类里面有个方法,这个方法返回这个类的一个对象,有什么用?
如题,下面是代码:
一系列import
public final class ConnectionManager {
private static ConnectionManager instance;
private Map<String, DBConnector> dsMap;
private ConnectionManager() throws Exception {
this.dsMap = new HashMap(5);
}
public static final ConnectionManager getInstance() {
if (instance == null) {
try {
instance = new ConnectionManager();
}catch (Exception e) {
e.printStackTrace();
}
}
return instance;
}
public final synchronized Connection getConnection(String connectionName) {
.......省略
}
}
----------------------------------------------------------------------------------------------------
Connection conn = ConnectionManager.getInstance().getConnection("mydb");
上面这句是原文,为什么不简单写成ConnectionManager.getConnection("mydb");
有一些代码省略了,需要的话我可以发
------解决方案--------------------
可用分可以转换成下载积分