Should I use the @Override tag when implementing the interface method?

Should I put an @Override tag if I implement an interface method? I know that the @Override tag should be there when you override the superclass method (and not the interface). But what about implementing an interface method?

+3
source share
1 answer

Well yes :

You should use @Override whenever possible. This prevents simple manufacturing errors. Example:

@Override
public boolean equals(MyObject mObj){
    // code ...
}

This does not compile because it incorrectly overrides the values.

The same goes for methods that implement the interface (1.6 and above) only) or override the class of the superclass Method.

+7

Source: https://habr.com/ru/post/1768162/


All Articles