How to implement something similar to the @Override java annotation?

前端 未结 2 1735
眼角桃花
眼角桃花 2021-02-04 19:36

With this jdk code in ../java/lang/Override.java,

package java.lang;
import java.lang.annotation.*;
@Target(ElementType.METHOD)
@Retention(Retentio         


        
2条回答
  •  失恋的感觉
    2021-02-04 19:48

    which is nothing more than an interface.

    So,

    How does interface java.lang.Override syntax help java compiler to detect above error at compile time?

    That's right. Override is nothing more than an interface. The actual work is done by the java compiler. How the compiler does this is not specified.

    Here are some links that explain how to work with an AnnotationProcessor to implement something similar to @Override :

    1. Processor Java doc
    2. Java annotation processing tool
    3. Code generation using AnnotationProcessor
    4. Annotation Processor, generating a compiler error
    5. Source code analysis using Java 6 API
    6. Playing with Java annotation processing

提交回复
热议问题