简体   繁体   中英

What is the syntax of the @Override annotation

I recently found that ( http://www.javabeat.net/articles/30-annotations-in-java-50-2.htmlthe )syntax of the @Override annotation is

@Retention(RetentionPolicy.CLASS)
    @Target(ElementType.RUNTIME)
    public @interface Override 
    {
    }

But I think the following.Since it can be applied only to methods and since it inform this to compiler.

@Retention(RetentionPolicy.CLASS
    @Target(ElementType.METHOD)
    public @interface Override 
    {
    }

Please tell me which one is correct. Please explain, if i am wrong.

Thanks.

Both are wrong; it is defined (according to javadoc ) as

@Target(ElementType.METHOD)
@Retention(RetentionPolicy.SOURCE)
public @interface Override 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM