Why do the java.util.Calendar before () and after () methods take an object as an argument and simply return false if the past object is not a Calendar?

It was a WTF moment for me ... I know that Java Date / Calendar classes should be horrible, but why do this?

Does it just make it easy to introduce subtle errors, or am I missing something?

+6
source share
1 answer

I believe the original reason was that the methods should have been "compatible" with the compareTo () method on the Comparable interface, which sets the Object argument (although this has clearly improved with the introduction of generics syntax). Essentially before (), this is the same as compareTo (..) <0 - and uses this to actually compare internally.

In principle, this is a bad legacy. We hope that we can all go over to the Java 8 libraries and pretend that the Calendar never existed.

+3
source

Source: https://habr.com/ru/post/978618/


All Articles