为什么java.sql.Timestamp扩展java.util.Date [英] Why does java.sql.Timestamp extend java.util.Date

查看:302
本文介绍了为什么java.sql.Timestamp扩展java.util.Date的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我看到这个时,我感到困惑:

When I saw this I got baffled:

  public class Timestamp extends java.util.Date {
    //...
    public boolean equals(java.lang.Object ts) {
      if (ts instanceof Timestamp) {
        return this.equals((Timestamp)ts);
      } else {
        return false;
      }
    }
    public int hashCode() {
        return super.hashCode();
    }

它确实以粗体Note记录在案 (请参见 https://docs.oracle.com/javase/7/docs/api/java/sql/Timestamp.html )

It is indeed documented with a bold Note (see https://docs.oracle.com/javase/7/docs/api/java/sql/Timestamp.html)

对我来说,做出如此糟糕的决定可能是什么原因? 与java.util.Date对象进行比较时,为什么不调用super.equals(this)以使相等比较对称?

What could be the cause to make such a, to me, very bad decision? Why not call super.equals(this) when compared to a java.util.Date object to make the equal comparison symmetrical?

推荐答案

相反,请使用java.time

正如其他人所述:

Instead, use java.time

As others stated:

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆