The analyzer has detected a situation where a method of the base class or interface is not overridden by another method with a similar signature.
Consider a synthetic example:
public class Base
{
public String someThing()
{
return "Base";
}
}
public class Derived extends Base
{
public String something() // <=
{
return "Derived";
}
}
In this code, when writing a method to override the 'someThing' method of the 'Derived' class, the programmer misspelled the method's name. This typo will make method overriding impossible, and its effect will reveal itself when you attempt to use polymorphism:
...
List<Base> list = new ArrayList<>();
list.add(new Base());
list.add(new Derived());
StringBuilder builder = new StringBuilder();
for (Base base : list)
{
builder.append(base.someThing());
}
String result = builder.toString();
...
Because of that spelling mistake, the 'result' variable will be assigned the 'BaseBase' string instead of the intended 'BaseDerived'.
Java provides the '@Override' annotation to secure you from possible mistakes when overriding methods. If a method marked with this annotation is not overriding any method, the compiler will warn you and abort compilation.
The fixed version:
public class Base
{
public String someThing()
{
return "Base";
}
}
public class Derived extends Base
{
@Override
public String someThing() //ok
{
return "Derived";
}
}
The following several examples demonstrate other situations that will trigger the warning.
import first.A;
public class Base
{
public void someThing(A input)
{
...
}
}
import second.A;
public class Derived extends Base
{
public void someThing(A input) // <=
{
...
}
}
The spelling of the 'input' argument's name is the same in both method declarations, but these types are located in different packages, 'first' and 'second', which will result in method overloading rather than overriding.
package first;
public class Base
{
void someThing()
{
...
}
}
package second;
import first.Base;
public class Derived extends Base
{
void someThing() // <=
{
...
}
}
In this example, the classes 'Base' and 'Derived' are located in different packages, 'first' and 'second' respectively. The 'someThing' method of the 'Base' class is declared without any modifiers and, therefore, has the default access level (package-private), which makes it inaccessible to the 'Derived' class located in a different package. Therefore, the method will not be overridden, and the analyzer will warn you about that.