Should I add an @Override annotation when implementing abstract methods in Java?

后端 未结 4 548
半阙折子戏
半阙折子戏 2020-12-24 10:26

When overriding a non-virtual method in Java, use of the @Override annotation is recommended, but what if I implement an abstract method? Should I use @Ov

4条回答
  •  暖寄归人
    2020-12-24 11:12

    Yes - again, it tells the compiler, "I really want to be overriding a method here. If there isn't a corresponding method to override, I've made a mistake and want to be told about it!"

    Personally I think it's a pity that this is just an annotation rather than part of the language (as it is in C#) but that's the benefit of hindsight, of course.

提交回复
热议问题