/** ???? * Constructs a new instance of the {@code Calendar} subclass appropriate for the ???? * default {@code Locale} and default {@code TimeZone}, set to the current date and time. ???? */ ??? public static synchronized Calendar getInstance() { ??????? return new GregorianCalendar(); ??? }
2016-07-23
Calendar不能用new的方式去實例化,你可以看一下這個類的源碼:
/**
???? * Constructs a new instance of the {@code Calendar} subclass appropriate for the
???? * default {@code Locale} and default {@code TimeZone}, set to the current date and time.
???? */
??? public static synchronized Calendar getInstance() {
??????? return new GregorianCalendar();
??? }
可以看到,當你調用它的getInstance()方法后,它會返回這個類的實例。