Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eclipse: always notice error when use @Override [duplicate]

I don't know why each time I implements a class. when I use @Override Eclipse always notice error:

the method A of type B must override a superclass method

(With method A is method that I override and B is the current class I work with)

And Eclipse recommend delete @Override

But with the same code, I work on Idea, no error found.

Who can tell me why,please.

thanks :)

@Edit: Oh, I don't post exactly code because It happend for all when I implement sth: for example:

public class helloworld implements Runnable {
    @Override //this line no-error with Idea and error with eclipse:the method run of type helloworld must be override a super class
    public void run(){
    }
like image 519
hqt Avatar asked Feb 09 '12 03:02

hqt


People also ask

Is @override annotation necessary?

@Override @Override annotation informs the compiler that the element is meant to override an element declared in a superclass. Overriding methods will be discussed in Interfaces and Inheritance. While it is not required to use this annotation when overriding a method, it helps to prevent errors.

Does @override do anything?

The @Override annotation indicates that the child class method is over-writing its base class method. It extracts a warning from the compiler if the annotated method doesn't actually override anything. It can improve the readability of the source code.


1 Answers

Java 5 only properly supports this annotation on methods you override when subclassing. Starting with Java 6 you can also use this annotation on methods that implement methods from an interface.

like image 156
Vadim Avatar answered Sep 22 '22 09:09

Vadim