Is there any reason to declare optional parameters in an interface?

后端 未结 5 478
星月不相逢
星月不相逢 2020-12-09 16:16

You can declare optional parameters in an interface method but implementing classes are not required to declare the parameters as optional, as Eric Lippert explained. Conver

5条回答
  •  借酒劲吻你
    2020-12-09 17:16

    It is useful in that the interface can declare them the way it wants, so you get the exact flexibility that you wanted when making the interface. In other words, an implementer in a derived class can make the parameter optional, can make it required, etc. as desired. If it isn't optional, the derived classes must have it.

    Your example above shows just that -- flexibility in the derived classes.

提交回复
热议问题