Community
Participate
Working Groups
Now that Java has the @Override tag, it would be nice if the compiler could enforce this, by giving a warning or error if a method overrides another without the @Override tag being present. This should be available in the "JDK 5.0 options" part of the Errors/Warnings preferences.
+1. IMO, the @Override annotation doesn't make much sense if it is only optional.
+1. With the advent of covariance and generics, overriding rules have become more complex, and checking @Override annotations certainly helps against unwanted overriding of methods.
Good suggestion
Option added. Enabled it through our some of our test suites, and adapted test results accordingly. Fixed
Added optional compiler diagnosis to flag method overriding a superclass method, but missing proper @Override annotation. Corresponding problem ID is: IProblem.MissingOverrideAnnotation * COMPILER / Reporting Missing @Override Annotation * When enabled, the compiler will issue an error or a warning whenever encountering a method * declaration which overrides a superclass method but has no @Override annotation. * - option id: "org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotation" * - possible values: { "error", "warning", "ignore" } * - default: "warning"
Any opinion whether this warning should be on by default ?
IMO, only few people use annotations at all. Even most 5.0 JDK rarely use @Override. I suggest to set this to ignore as default, even if the option can be very useful.
Agreed. Unless the team already has the convention of using @Override, it would create a lot of warnings almost all of which are spurious. I'm in the happy situation of starting a new project with no existing code, but most other people aren't!
sold
Verified in I20050330-0500