【问题标题】:Type Date return content类型日期返回内容
【发布时间】:2018-05-06 22:14:27
【问题描述】:

请参阅下面的内容,对日期类型的返回内容感到困惑

@Override
public int maxCapacity() {
    return 3;
}
@Override
public String area() {
    return "10";
}
@Override
public Date whenBuilt() {
    return ***[What should I return here?]***
}

【问题讨论】:

  • 某个 Date 实例?
  • 你能举个例子吗?
  • new Date() 为您提供当前日期

标签: return


【解决方案1】:

Date 方法必须返回 Date 实例或 null..

您可以只使用return new Date();,但它总是会更新日期。

方法whenBuilt 看起来像是过去的某个日期,所以你应该做一些日期,例如在构造函数中。

class A {
  private final Date createdAt;
  A() {
    createdAt = new Date();
  }
  public Date whenBuilt() {
    return createdAt;
  }
}

@Override 指向您的类的注释是从某个基类扩展而来的。
尝试检查基类,可能构建日期已经在那里。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-19
    • 2017-12-15
    • 1970-01-01
    • 2019-05-01
    相关资源
    最近更新 更多