Equivalent of Java 1.6 @Override for interfaces in C#

后端 未结 4 949
慢半拍i
慢半拍i 2021-02-13 03:19

This question gives the answer that Java\'s @Override has the C# equivalent of the override keyword on methods. However, since Java 1.6 the @Override annotation can

4条回答
  •  情歌与酒
    2021-02-13 03:48

    The @Override for interface in Java means 'implements'. When in Java a class implements an interface method and that method's signature is changed or the method is removed from the interface later the java compiler starts complaining about it.

    This way it prevents the method to become 'dead code', you either have to remove the @Override annotation (so the method becomes a normal method) or remove or change the method to match the interface again. This is a very nice feature to keep your code clean. I would like C# to have this feature too.

    I use explicit implementing as much as I can.

    By the way: Resharper shows it when a method implements an interface method.

提交回复
热议问题