Why is the Java date API (java.util.Date, .Calendar) such a mess?

前端 未结 4 1198
南笙
南笙 2020-11-21 21:58

As most people are painfully aware of by now, the Java API for handling calendar dates (specifically the classes java.util.Date and java.util.Calendar

4条回答
  •  Happy的楠姐
    2020-11-21 22:38

    Java's early APIs are nothing more than a product of their time. Immutability only became a popular concept years after that. You say that immutability is "obvious". That might be true now but it wasn't then. Just like dependency injection is now "obvious" but it wasn't 10 years ago.

    It was also at one time expensive to create Calendar objects.

    They remain that way for backwards compatibility reasons. What is perhaps more unfortunate was that once the mistake was realized the old class wasn't deprecated and new date/time classes were created for all APIs going forward. This has to some degree occurred with the JDK 8 adoption of a JodaTime like API (java.time, JSR 310) but really it's too little too late.

提交回复
热议问题