Which of the two is the more recommended way to get a calendar object or is there no difference? I read once that the Calendar object is a pretty "heavy" object and they recommened using the latter below. Any thoughts? Calendar cal = Calendar.getInstance(); GregorianCalendar cal = new GregorianCalendar();
Joined: Dec 10, 2001
GregorianCalendar is the type meant to represent the standard calendar used by most of the world (according to the class documentation). For that reason, I'd probably prefer it in most situations I'm likely to make use of a calendar.
I'm not sure what is meant by a "heavy" object in this context. I personally use Calendar.getInstance(), because that the most loosely coupled reference (and takes less typing, so it's good in two ways ) Since getInstance returns the Locale-based subclass, I am more than likely to wind up with a GregorianCalendar anyway, unless my code is being run in a strange locale. And if my code is being run in a strange locale, then it's a good thing I used the more loosly-coupled Calendar.
Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
Joined: May 05, 2000
The Calendar getInstance method eventually runs this method with the default zone and locale:
All Calendar.getInstance() does is create a new GregorianCalendar object with the default zone and locale. [ June 06, 2003: Message edited by: Thomas Paul ]