开发者

Why doesn't java.util.Calendar make use of Enums?

I sometimes get frustrated by the lack of type safety with j.u.Calendar and wondered if there was a good reason for not using enums in the Calendar API that has gone over my head, or if the only reason is that it was probably written before enums were a part of the开发者_如何转开发 language and is not worth breaking old code.

A secondary sub-question is: Is it worth my time to create a more type safe wrapper around the Calendar class or has this been done before?


Summary: Calendar has been around since Java 1.1 whereas Enums only made it in Java 5, JODA Time is considered the best replacement package for Calendar.


Enums weren't part of Java when Calendar was written. They haven't been added due to neglect, fear of breaking backward compatibility, insufficient priority, developers who don't agree with you - take your pick.


It was implemented before enums made their way into the language (enums arrived at version 5).

JODA Time is widely considered the best replacement package.


The Calendar class has been around since Java 1.1, which is why it doesn't use Enums.

I strongly recommend using Joda time rather than the train-wreck that is java.util.Calendar.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜