6

Is it just me, or is Java's Override annotation actually useless when programming in a decent IDE?

Yes, I understand that the Override annotation prevents me from accidentally not overriding a super method by misspelling the method name or messing up the method parameters. However, common sense tells me this is very unlikely to happen in modern IDEs, for the following reasons:

  • The IDE shows a marker (i.e. a small icon) on the left side of the editor that indicates whether the method is overridden/overriding. Therefore, no explicit Override annotation is needed to show the Override intention.
  • If I'm about to rename a method and I see such an override marker, I never, ever edit the method name directly - I instinctively reach out for the keyboard shortcut that opens the IDE's renaming assistant. Likewise, if I intend to change the method signature and I see the override marker, I instinctively use the IDE's method signature assistant instead of doing it by hand (except for very simple cases). Method names and signatures are thus almost always changed correctly, so adding Override annotations becomes (in my opinion) little more than a paranoid and useless safety check - same as spreading 'final' all over the place.

Sure, if you have to write your Java code in Notepad or whatever, the Override annotation obviously helps. But my point is, in a modern IDE, the increase in safety provided by this annotation is not worth the decrease in readability. Any opinions?

3 Answers 3

6

Well you have to trust yourself to see those markers. There is a human element to it and humans are fallible. From personal experience I often tend to overlook those warnings and 'markers'. On the other hand, the compiler is far more exacting and if you annotate a method with Override it will make sure that you are really overriding a superclass method.

1
  • 1
    Plus, in most IDEs the IDE will put a red squiggle (or equivalent compile warning) on the @Override if it isn't overriding something. This is useful as people who are used to an IDE notice when they are warned the code won't compile, but may not necessarily notice the override marker changing.
    – user545680
    Jun 20, 2011 at 8:04
6

If you @Override something which is not overridden this is obvious in an IDE. However if you remove a method or change its signature in a parent, it is not obvious all the places that used Override this method signature. Using an IDE to perform the remove/change will help but you may not get every reference if the right module/version is not checked out and used.

1
  • 1
    +1. Changing the signature in a base class is what I think is the most common reason to broken functionality.
    – Kaj
    Jun 20, 2011 at 8:13
4

Yes, it is pretty much useless. For people who find it useful, good for them. But the scenarios they used to justify it is not realistic. The fact is, many don't use @Override, and they never encountered any problem it supposedly solve.

python dude: you didn't mention keyboard shortcut(Ctrl-O in IntelliJ) when overriding a method. I never manually type signature of the method I'm overriding, so there won't be typo to begin with.

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.