• Post Reply Bookmark Topic Watch Topic
  • New Topic

Calendar class......have no constructor  RSS feed

 
harsh garg
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why calendar class provides no public constructor? :roll:
[ November 06, 2008: Message edited by: Bear Bibeault ]
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by harsh garg:
why calendar class provides no public constructor? :roll:


The class is abstract -- which could be the reason. Regardless, you couldn't instantiate a Calendar object (because it is abstract) even if the constructor was public.

Henry
 
Campbell Ritchie
Marshal
Posts: 56545
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's not needed. Calendar is an abstract class and it provides a protected constructor to be called indirectly via its subclasses. There is only one subclass in the API, which is GregorianCalendar, which has lots of public overloaded constructors.
 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But it's not the only subclass in the library. The Calendar.getInstance usually return a GregorianCalendar object, but depending on the locale it can also return an instance of sun.util.BuddhistCalendar (hidden class) or java.util.JapaneseImperialCalendar (class with default access, so not public). So if possible use Calendar.getInstance instead, and then set the values using Calendar.set(int, int) or Calendar.setTime(Date).
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!