写代码的时候用到了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)方便,还要思考
探讨了Java中newDate(Strings)方法被标记为过时的原因,及如何使用DateFormat.parse(Strings)替代,避免代码提示过时,保持代码的现代性和效率。

1482

被折叠的 条评论
为什么被折叠?



