Overloads are considered at compile-time; overrides are considered at execution time.
Timestamp overloads after
, it doesn't override an existing method - so your oneDate.after(twoDate)
is only considering the methods in java.util.Date
; furthermore even if you use one.after(twoDate)
it would still only use after(Date)
because the compile-time type of twoDate
is Date
rather than Timestamp
.
If you call one.after(two)
then that will use Timestamp.after(Timestamp)
.
Date.after(Date)
only considers the milliseconds - but Timestamp
only passes an integral number of seconds to the constructor of Date
, so oneDate
and twoDate
have an equal millisecond value in Date
, even though you passed different values to the constructors.
It's worth noting this bit in the docs for Timestamp
though:
Due to the differences between the
Timestamp class and the java.util.Date
class mentioned above, it is
recommended that code not view
Timestamp values generically as an
instance of java.util.Date. The
inheritance relationship between
Timestamp and java.util.Date really
denotes implementation inheritance,
and not type inheritance.
Sounds like a pretty poor use of inheritance to me, to be honest - but then Java's got plenty of those :(
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…