On Mon, Apr 5, 2021 at 9:04 PM yiyus <yiyu....@gmail.com> wrote: > > then I guess you mean that interface { MyInt } will accept any type > > argument whose underlying type is the same as the underlying type of > > MyInt. But that seems strange. There is no connection between MyInt > > and MyInt2, except that they happen to be defined in terms of the same > > underlying type. > > This is an excellent example. Indeed, I think that MyInt and MyInt2 should > satisfy the same constraints (because they support exactly the same > operations). Just like MyString and MyString2 will implement the Stringer > interface if they happen to have a String method, and there is no way to > constrain the types which can implement Stringer, I think that any type > that can be used in a generic function like an int should satisfy > interface{int} (and therefore also interface{MyInt} and interface{MyInt2}). >
But they don't necessarily support exactly the same operations if they have different methods. So maybe you mean that MyInt and MyInt2 should satisfy the same constraints if they have the same underlying type and happen to support the same method sets. -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CA%2BYjuxsXpMcQTGVbSFvmS%2BhSsot8BT7_RVx1Pf_euhtdRuZSbw%40mail.gmail.com.