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

查看:51
本文介绍了不推荐使用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(年+ 1900,月,日期,小时,分钟)

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

根据API文档的建议

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

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