Java 的 Date(...) 构造函数已弃用;这意味着什么? [英] Java's Date(...) constructor is deprecated; what does that mean?

查看:41
本文介绍了Java 的 Date(...) 构造函数已弃用;这意味着什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试像这样创建一个 Date:

I'm trying to create a Date like this:

date = new Date(year-1900, mon-1, day, hrs, min, sec);

和 Eclipse 给了我这个警告:构造函数 Date(int, int, int, int, int) 已弃用".

and Eclipse gives me this warning: "The constructor Date(int, int, int, int, int) is deprecated".

不推荐使用构造函数意味着什么,我该怎么办?

What does it mean for a constructor to be deprecated, and what can I do?

推荐答案

弃用的字面意思是不赞成,但更准确的翻译会停用.已弃用意味着此方法仍然可用,但您不应使用它.将逐步淘汰.有一种新方法可以做同样的事情.不推荐使用的方法用特殊的 Javadoc 注释标记:

Deprecated literally means disapproved of, but a more accurate translation would be retired. Deprecated means this method is still usable, but you should not use it. It will gradually be phased out. There is a new method to do the same thing. Deprecated methods are marked with a special Javadoc comment:

/**
 *@deprecated Please now use newMethod()
 *@see newMethod()
 */

使用:

  • Calendar.set(year + 1900, month, date, hrs, min)

  • GregorianCalendar(year + 1900, month, date, hrs, min).

按照API 文档的建议.

这篇关于Java 的 Date(...) 构造函数已弃用;这意味着什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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