GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • CodeQL documentation
  • CodeQL overview
  • Writing CodeQL queries
  • CodeQL language guides
  • QL language reference
  • CodeQL standard-libraries
  • CodeQL query help
  • CodeQL repository
  • QL publications
  • CodeQL query help for C and C++
  • CodeQL query help for C#
  • CodeQL query help for GitHub Actions
  • CodeQL query help for Go
  • CodeQL query help for Java and Kotlin

This view

  • Original page
  • New address

GeezerVison is showing codeql.github.com — Interface cannot be implemented — CodeQL query help documentation

Interface cannot be implemented¶

ID: java/unimplementable-interface
Kind: problem
Security severity: 
Severity: warning
Precision: very-high
Tags:
   - quality
   - maintainability
   - useless-code
Query suites:
   - java-code-quality.qls
   - 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¶

  • Help - Eclipse Platform: Java Compiler Errors/Warnings Preferences.

  • Java Language Specification: 9.2 Interface Members.

  • © GitHub, Inc.
  • Terms
  • Privacy
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.