Interface cannot be implemented¶
ID: java/unimplementable-interfaceKind: problemSecurity severity: Severity: warningPrecision: very-highTags: - quality - maintainability - useless-codeQuery 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 onjava.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 inObject. Otherwise you should delete the interface.
Example¶
In the following example, the interfaceI is useless because theclone method must return typejava.lang.Object:
interfaceI{intclone();}classCimplementsI{publicintclone(){return23;}}
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 typefound : intrequired: java.lang.Object public int clone() { ^1 errorReferences¶
Help - Eclipse Platform:Java Compiler Errors/Warnings Preferences.
Java Language Specification:9.2 Interface Members.