Why can i have only one instance of Calendar object

后端 未结 4 2072
故里飘歌
故里飘歌 2020-12-06 04:15

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 documentat

4条回答
  •  失恋的感觉
    2020-12-06 05:05

    You can have as many instances of Calendar as you want ... modulo that it is an abstract class, so you are talking about of instances of child classes of Calendar.

    Perhaps you think that the getInstance() method returns a singleton object? It doesn't. It creates and returns a new object each time you call it.

    (The javadoc doesn't explicitly state that the calendar is not a singleton, but it says "The Calendar returned is based on the current time ...". That implies that it is returning a new object each time ... because the current time keeps changing. And anyway, that's what the method does if you'd care to look at the source code.)

提交回复
热议问题