单例模式应该满足每个该类的对象都指向同一块内存区域吧,Calendar显然满足。
但在这里(http://raychase.iteye.com/blog/1471015)看到说“这种形式可以看做是单例的一个变体。”,变体怎么理解?
package test;
import java.util.Calendar;
public class LeakTest {
/**
* @param args
*/
public static void main(String[] args) {
Calendar c1 = Calendar.getInstance();
Calendar c2 = Calendar.getInstance();
Runtime run1 = Runtime.getRuntime();
Runtime run2 = Runtime.getRuntime();
System.out.println("c1.equals(c2) is " + c1.equals(c2));
System.out.println("c1 == c2 is " + (c1 == c2));
System.out.println("run1.equals(run2) is " + run1.equals(run2));
System.out.println("run1 == run2 is " + (run1 == run2));
}
}
MYYA
繁华开满天机
相关分类