問題描述
我只是想知道...
為什么我只能有一個 Calendar 對象的實(shí)例.有沒有理由讓它成為單身人士?
why can i have only one instance of Calendar object. Is there a reason for it to be a singleton?
我已嘗試閱讀 文檔 但他們沒有提到為什么需要這樣做.快速谷歌搜索沒有給我任何答案.
I have tried to read the documentation but they didn't mention why this is needed. And a quick google search didn't give me any answers.
推薦答案
Calendar 不是單例,它是一個抽象類.getInstance
方法是一個工廠方法,它返回 Calendar 類的具體實(shí)現(xiàn).
Calendar is not a singleton, it is an abstract class. The getInstance
method is a Factory method that returns a concrete implementation of the Calendar class.
在 Google 上搜索 java.util.Calendar 源代碼,您將了解它是如何工作的.
Search Google for java.util.Calendar source code, and you will see how it works.
這篇關(guān)于為什么我只能有一個 Calendar 對象實(shí)例的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!