Do I need to put @Override when implementing the method of the interface?
Read about @Override in the Java document.
"@Override indicates that when defining a method, it overrides a higher-class method. If you have @Override and you haven't overridden a higher-class method, the compiler will send an error message."
That's what it says. I don't think the interface is super class, is it not?
oop java interface annotations
Put @Override on it if you can. That way, you can prevent the same mistakes below
class C {
@Override
public boolean equals(SomeClass obj){
// // code ...
}
}
The above code cannot be compiled because it does not properly override public boolean equals(Objectojb).
You should use @Override when implementing methods in interface (java 1.6 or higher) or when overriding methods in higher classes.
© 2024 OneMinuteCode. All rights reserved.