tags:

views:

71

answers:

2

From the javadoc of Calendar.before(Object when):

Returns whether this Calendar represents a time before the time represented by the specified Object. This method is equivalent to:

compareTo(when) < 0

if and only if when is a Calendar instance. Otherwise, the method returns false.

Why does it accepts an Object if when someone passes something that's not a Calendar instance it returns false? Why not just accepting a Calendar instance? This kept me watching for uncorrect results in a functionality for quite some time.

+5  A: 

I think there is no particular reason for that. java.util.Calendar has some design issues we have have to live with, unfortunately.

DerMike
+1. Note that the Date object (whose design issues Calendar was supposed to address) has a before method that does not take an Object (but another Date). Not a particularly consistent API.
Thilo
By "live with" do you mean dump in favor of Joda Time?
ILMTitan
A: 

I think this may be to provide encapsulation by using polymorphic behaviour in the before() method.

JVM