Reading <Effective Java>
来源:互联网 发布:qq群搜索排名优化 编辑:程序博客网 时间:2024/04/20 04:36
In item 3 of Effective Java, a new way of creating an Singleton class with Enum is introduced.
public enum Singleton{
INSTANCE;
public void method{ ... }
}
And just access the singleton with Singleton.INSTANCE
This is pretty neat to implement and I shall try it out next time when I am working on Singleton.
Item 5: avoid creating unnecessary objects
An example is give in the book:
public boolean isBabyBoomer(){
Calendar gmtCal = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
}
compared to
static {
Calendar gmtCal = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
}
public boolean isBabyBoomer(){
return .... // something that uses gmtCal...
}
The second approach is much more efficient as only one instance of Calendar is obtained, instead of creating one each time isBabyBoomer is called.
- Reading <Effective Java>
- Begin reading 'Effective c++'
- Effective C++ Reading Notes
- reading 《effective c++》
- reading《effective c++》三
- reading《effective c++》四
- Reading note of Effective C++
- Effective C++ (reading note)
- 《Effective C++》 Reading Note 1
- 《Effective C++》 Reading Note 2
- 《Effective C++》 Reading Note 3
- 《Effective C++》 Reading Note 4
- iOS Reading from private effective user settings?
- Reading <<Java SOA Cookbook>>
- Effective Java
- Effective Java
- Effective Java
- Effective Java
- test命令在shell脚本中的应用
- 如果饭店不是自己的,最好别去
- UI 实现多线程方式之四 GCD之函数作为参数
- java程序防止sql注入的方法
- 一道受用终身的测试题
- Reading <Effective Java>
- iOS编程------SQLite / 数据库
- Sublime Text 3使用方法简介
- 黑马程序员——C语言日志——static和extern
- Django如何重设Admin密码
- 75道逻辑思维题
- Dubbo 入门实例 本地伪集群测试Demo
- C# Enum,Int,String的互相转换 枚举转换
- HDU 1070.Milk【最优解】【10月5】