的javac -Xlint:覆盖不工作 [英] javac -Xlint:overrides not working

查看:364
本文介绍了的javac -Xlint:覆盖不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让我的Java构建的时候我有一个覆盖超类方法,而无需指定@Override注释一类失败。

I'm trying to get my java build to fail when I have a class that overrides a superclass method without specifying the @Override annotation.

构建正在通过蚂蚁做的,我已经添加了以下元素到我的<&javac的GT; 任务:

The build is being done via ant, and I've added the following elements to my <javac> task:

<compilerarg value="-Werror"/>
<compilerarg value="-Xlint:unchecked,overrides"/>

选中选项被跟踪,但覆盖选项被忽略。我也试过分开两个 Xlint 选项分成两个独立的&LT; compilerarg&GT; 元素,都无济于事。我误解这个选项做什么?

The unchecked option is being followed, but the overrides option is being ignored. I also tried separating the two Xlint options into two separate <compilerarg> elements, to no avail. Am I misunderstanding what this option does?

一注:这是JDK6 MacOSX上(10.6)。我能运行到特定OSX-错误?

One note: this is JDK6 on MacOSX (10.6). Could I be running into a OSX-specific bug?

推荐答案

我相信你误解了 Xlint:重写行为

据我了解,启用此检查将导致编译器发出警告(或者错误),当它遇到以 @覆盖注释的方法实际上并不重写超类方法。这不,但是,检查所有覆盖的方法是否正确注解。

To my knowledge, enabling this check will cause the compiler to emit warnings (or maybe errors) when it encounters a method annotated with @Override that does not actually override a superclass method. It does not, however, check that all overridden methods are annotated correctly.

编辑:只是测试它。编译器会发出当您指定 @覆盖在不重写超类方法,使用或不使用 Xlint 选项。

Just tested it. The compiler will emit an error when you specify @Override on a method that does not override a superclass method, with or without the Xlint option.

rel=\"nofollow\"> Oracle的网站没有按在

The documentation on Oracle's website doesn't even mention the Xlint:overrides option so I'm guessing it's not implemented.

这篇关于的javac -Xlint:覆盖不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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