javac 显示错误且没有警告
我正在使用 Sun 的 javac 1.6.0_26。我这样调用它:
javac -Xlint -encoding UTF-8
通常如果有错误,则只显示错误。然而,这段代码
class Test{
public static void main(String args[]) {
java.util.Date d = new java.util.Date();
system.out.println(d.getDate());
}
会产生警告和错误:
java:5: warning: [deprecation] getDate() in java.util.Date has been deprecated
system.out.println(d.getDate());
^
java:5: package system does not exist
system.out.println(d.getDate());
所以我的问题是:当没有错误(绝不是两者)时有任何和所有警告时,如何使 javac 仅显示错误(没有警告)?
I'm using Sun's javac 1.6.0_26. I invoke it like this:
javac -Xlint -encoding UTF-8
and usually if there are errors only them are displayed. However this code
class Test{
public static void main(String args[]) {
java.util.Date d = new java.util.Date();
system.out.println(d.getDate());
}
produces both warning and error:
java:5: warning: [deprecation] getDate() in java.util.Date has been deprecated
system.out.println(d.getDate());
^
java:5: package system does not exist
system.out.println(d.getDate());
So my question is: how do I make javac show only errors (without warnins) when there are any and all warnings when there are no errors (never both)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
javac
-nowarn
中有一个标准选项,可以禁用警告消息。您可以从 javac-options 获取更多信息There is a standard option in javac
-nowarn
which disable warning messages. You can get more informations from javac-options忽略编译器警告不是一个好主意。大多数时候它们确实很重要。仅当您非常确定要忽略警告时,才可以添加注释:
就像您在想:让我先修复错误,然后修复警告。但我不认为这是一种很好的工作方式。为了解决警告,您可能必须更改大量代码,并且所有其他错误解决工作都是不需要的,因为您需要其他代码。从全球角度看待问题总是好的。
It's a bad idea to ignore the compiler warnings. Most of the time they are really important. Only if you are very sure that you want to ignore a warning you can add an annotation:
It's like you are thinking: Let me first fix errors and afterwards the warnings. But I don't think that is a nice way of working. To solve warnings, you might have to change a lot of code, and all your other error-solving work was unneeded because you needed other code. It is always good the look at a problem globally.