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.
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"/>
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?
One note: this is JDK6 on MacOSX (10.6). Could I be running into a OSX-specific bug?
I believe you are misunderstanding the
Xlint:overridesbehaviour.To my knowledge, enabling this check will cause the compiler to emit warnings (or maybe errors) when it encounters a method annotated with
@Overridethat does not actually override a superclass method. It does not, however, check that all overridden methods are annotated correctly.EDIT: Just tested it. The compiler will emit an error when you specify
@Overrideon a method that does not override a superclass method, with or without theXlintoption.The documentation on Oracle’s website doesn’t even mention the Xlint:overrides option so I’m guessing it’s not implemented.