本文介紹了為什么我只能有一個 Calendar 對象實例的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
限時送ChatGPT賬號..
我只是想知道...
為什么我只能有一個 Calendar 對象的實例.有沒有理由讓它成為單身人士?
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 類的具體實現.
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.
這篇關于為什么我只能有一個 Calendar 對象實例的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!