Calendar 类是一个抽象类,抽象类是不能实例化对象的。可是我在看API的时候看到这样的描述:
“Calendar 提供了一个类方法 getInstance,以获得此类型的一个通用的对象。Calendar 的 getInstance 方法返回一个 Calendar 对象,其日历字段已由当前日期和时间初始化: Calendar rightNow = Calendar.getInstance();”
我对这个很不解,为什么这个抽象类Calendar 可以通过getInstance()返回Calendar 对象。希望各位大神给出指点。十分感谢!!!
Calendar rightNow = Calendar.getInstance()
First of all, abstract classes can have concrete implementation methods.
Secondly, take a look at the source code:
What this method ultimately returns is the specific implementation class, that is, the subclass, not the class that you understand as the instantiation of Calendar itself.