Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
119 views
in Technique[技术] by (71.8m points)

java - Why can i have only one instance of Calendar object

I was just wondering...

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.

Search Google for java.util.Calendar source code, and you will see how it works.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...