There is a class

class Base { public String toString() { return this.getClass().getName(); } } 

It overlaps the toString method without the @override notation. When compiled in IntelliJ IDEA 2016.3, I expect to see a warning, but it does not. Added the -Xlint , -Xlint:all , -Xlint:overrides parameters to the Compiler Settings -> Compiler -> Java compiler -> Additional command line parameters - had no effect. What am I doing wrong?

2 answers 2

The essence of the @override annotation is to check for the presence of the annotated method in the superclass and nothing more.

In case of method redefinition without annotation - there should be no warnings.

Now, if you specified the @override annotation for a method that is not in the superclass, then the IDE would notify you about this.

  • Clear. Thank. Is there no way to issue a warning in my case? When overriding an existing method without @Override? - Anton Shchyrov
  • @AntonShchyrov, I honestly do not know. By the way, a person asks a similar question. Maybe in the answers to it you will find something useful. - post_zeew

The answer was found in English SO https://stackoverflow.com/questions/4330275/javac-xlintoverrides-not-working Thank you @post_zeew

The compiler does not keep track of the absence of @Override (this directive forbids overlapping the missing method). But IDE can track itself. To do this, go to Settings -> Editor -> Inspections and configure the Missing @Override annotations parameter Missing @Override annotations . You can also deselect the checkbox with the options' ignore 'equals ()', 'hashCode ()' and 'toString () methods'.