尽管您的 IDE 对此有什么看法,但使用旧java.util.Date方法并没有那么糟糕。在常规的 Java 代码中,是的,请改用Calendar类,但由于历史原因,请三思而后行,不要使用那些“已弃用”的方法。
曾几何时,Java 是最酷的孩子——很奇怪,对吧?Web 浏览器没有这样的语言,有人说:“嘿,让我们给他们一种脚本语言,但是叫它什么,我不知道,很酷!” 因此,我们得到了 JavaScript——比 Java 更像是一种类似 Lisp 的语言,但没关系。
借用了一些 API,例如 Date 对象。然后,Java 决定它可以更好地处理日期和时间以及时区,弃用了setHours诸如
浏览器虽然有 JavaScript,但正在寻找自己的方式,并继续使用这些方法。有一些 JavaScript 库可以帮助处理日期,但在浏览器运行时中,Date 对象仍然看起来像旧的java.util.Date.
So when in GWT, write in Java where you like, but always remember that you are in a web browser - the underlying language just so happens to have native functionality that uses those deprecated methods - and they aren't going anywhere. Likewise, even though Object.wait() and notify() are legal, you can't use them, nor will your finalize() ever be invoked - these are just things you need to keep in mind when using Java to organize and maintain your library or application, and compiling to run in web browsers using JavaScript.