CodeQL documentation

Interface cannot be implemented

ID: java/unimplementable-interface
Kind: problem
Security severity: 
Severity: warning
Precision: very-high
Tags:
   - maintainability
   - useless-code
Query suites:
   - java-security-and-quality.qls

Click to see the query in the CodeQL repository

An interface that contains methods whose return types clash with protected methods on java.lang.Object can never be implemented, because methods cannot be overloaded based simply on their return type.

Recommendation

If the interface is useful, name methods so that they do not clash with methods in Object. Otherwise you should delete the interface.

Example

In the following example, the interface I is useless because the clone method must return type java.lang.Object:

interface I {
    int clone();
}

class C implements I {
    public int clone() {
        return 23;
    }
}

Any attempt to implement the interface produces an error:


InterfaceCannotBeImplemented.java:6: clone() in C cannot override
  clone() in java.lang.Object; attempting to use incompatible return
  type
found   : int
required: java.lang.Object
  public int clone() {
             ^
1 error

References

  • © GitHub, Inc.
  • Terms
  • Privacy