Are there any static duck-typed languages?

前端 未结 15 1026
我寻月下人不归
我寻月下人不归 2020-12-14 10:12

Can I specify interfaces when I declare a member?

After thinking about this question for a while, it occurred to me that a static-duck-typed language might actually

15条回答
  •  感情败类
    2020-12-14 10:26

    A brand new answer to this question, Go has exactly this feature. I think it's really cool & clever (though I'll be interested to see how it plays out in real life) and kudos on thinking of it.

    As documented in the official documentation (as part of the Tour of Go, with example code):

    Interfaces are implemented implicitly

    A type implements an interface by implementing its methods. There is no explicit declaration of intent, no "implements" keyword.

    Implicit interfaces decouple the definition of an interface from its implementation, which could then appear in any package without prearrangement.

提交回复
热议问题