How to enforce method signature for child classes?

后端 未结 5 1699
隐瞒了意图╮
隐瞒了意图╮ 2021-01-06 17:05

Languages like C#, Java has method overloads, which means if child class does not implement the method with exact signature will not overwrite the parent method.

How

5条回答
  •  我在风中等你
    2021-01-06 17:45

    By design, the language doesn't support checking the signatures. For an interesting read, check out:

    http://grokbase.com/t/python/python-ideas/109qtkrzsd/abc-what-about-the-method-arguments

    From this thread, it does sound like you may be able to write a decorator to check the signature, with abc.same_signature(method1, method2), but I've never tried that.

提交回复
热议问题