Would you put the annotation in implementation class methods? Does it serve any purpose? If you mistype or don’t have it, it is a compile error anyway.
Would you put the annotation in implementation class methods? Does it serve any purpose?
Share
I assume you are asking about annotating methods which are defined in an implemented interface, or as
abstractin a super class. In that case, you are correct that a typo in the method signature will result in a compile error with or without@Override. However, I think the annotation is still helpful to explicitly mark a method as implementing an interface. If the interface ever changes, having@Overrideannotations on all the implementing methods can help pinpoint which method signatures have changed and need to be updated.More importantly, as mklhmnn mentioned in his answer, if a method is removed from the interface, the
@Overrideannotation in your implementing class will cause a compile error. Without the annotation, you might not be aware that a method had been removed from the interface, which could lead to subtle bugs.