Manoj
Manoj

Reputation: 5867

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.

Upvotes: 0

Views: 435

Answers (1)

skaffman
skaffman

Reputation: 403471

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

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

Upvotes: 3

Related Questions