A
Arne Vajhøj
Harold said:And I repeat: it should be concrete. We don't have an abstract
StringBuilder and a bunch of polymorphic StringBuilder subclasses, even
though string encodings and characters and presentation are often
heavily locale-dependent, so why an abstract and polymorphic date
builder type?
Very simple answer.
Because there are only one StringBuilder and multiple Calendar's.
The only explanation I can think of, besides sheer perversity, is
because they gave one class multiple responsibilities.
No. See above.
Sure it is.
You can get that by adding the time zone offset to the time, for
Chrissake, and using a suitable DateFormat when converting to and from
user-visible or -supplied strings.
Try read the documentation of the Calendar class again.
You seem to have missed some methods.
Except that the set method doesn't let you. It only has the six
arguments years, months, days, hours, minutes, and seconds. So the natural
Calendar c = Calendar.getInstance();
c.set(yy,mm,dd,h,m,s);
Date d = c.getTime();
results in a date with a seemingly-random component when really the
above should suffice to yield a Date object dependent solely upon yy,
mm, dd, h, m, and s. Instead, to get such a Date object apparently
requires extra effort of some kind.
If you care about milliseconds you need to set milliseconds.
And there is a method for that.
And that, by itself, is sufficient to demonstrate conclusively that a
design flaw exists.
No - it only proves that programmers that does not read the
documentation produce lousy code.
Arne