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 — Missing Override annotation — CodeQL query help documentation

Missing Override annotation¶

ID: java/missing-override-annotation
Kind: problem
Security severity: 
Severity: recommendation
Precision: high
Tags:
   - quality
   - maintainability
   - readability
Query suites:
   - java-code-quality.qls
   - java-security-and-quality.qls

Click to see the query in the CodeQL repository

Java enables you to annotate methods that are intended to override a method in a superclass. Compilers are required to generate an error if such an annotated method does not override a method in a superclass, which provides increased protection from potential defects. An annotated method also improves code readability.

Recommendation¶

Add an @Override annotation to a method that is intended to override a method in a superclass.

Example¶

In the following example, Triangle.getArea overrides Rectangle.getArea, so it is annotated with @Override.

class Rectangle
{
    private int w = 10, h = 10;
    public int getArea() { 
        return w * h; 
    }
}
 
class Triangle extends Rectangle
{
    @Override  // Annotation of an overriding method 
    public int getArea() { 
        return super.getArea() / 2; 
    }
}

References¶

  • J. Bloch, Effective Java (second edition), Item 36. Addison-Wesley, 2008.

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

  • Java API Specification: Annotation Type Override.

  • The Java Tutorials: Predefined Annotation Types.

  • © 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.