java方法调用提示此方法已过时

写代码的时候用到了new Date(String s)被提示方法已过时

点进去看到了@Deprecated注解 被标注已经废弃(过时)

这个注解的意思简单来说就是加上该注解之后,表示可以调用但不建议调用,调用时会出现删除线。

同时,接口提供方既然明确是过时接口,那么有义务同时提供新的接口;作为调用方来说,有义务去考证过时方法的新实现是什么。

此注解可用于类上、方法上、属性上。暂时可用,后期可能会删除,所以不建议后来人使用。

方法上方也有注释

/**
 * Allocates a <code>Date</code> object and initializes it so that
 * it represents the date and time indicated by the string
 * <code>s</code>, which is interpreted as if by the
 * {@link Date#parse} method.
 *
 * @param   s   a string representation of the date.
 * @see     java.text.DateFormat
 * @see     java.util.Date#parse(java.lang.String)
 * @deprecated As of JDK version 1.1,
 * replaced by <code>DateFormat.parse(String s)</code>.
 */

由此可知为了避免提示过时应使用Dateformat.parse(String s)接口

保留这个接口的意义在于不用调整既有代码,导致以前开发的接口出问题

 

ps:new Date(String s)怎么想都比SimpleDateFormat初始化再parse(String s)方便,还要思考

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值