> Adding methods to a primitive type, or more generally adding methods > to a type defined in a different package, would cause different > packages to behave differently depending on whether they see the > methods. That would be confusing. It would meant that type > assertions would sometimes succeed and sometimes fail, depending on > the exact sequence of function calls used. > > Ian >
Understood, granted due to Go structural typing it's easy to confuse where the methods are coming from. but given the following, for example, // this allow new methods to be bounded to `String` type String string func Display(s string) { fmt.Prinln(s) } func main() { s := String("hello") // this wont work, even though there is enough information that `string` is the underlying type of `String` // but if we use `type String = string`, this will work, but no additional method binding is allowed. Display(s) // for `type String string`, we have to downcast it manually, but we can bind new methods Display(string(s)) // this works } Is it not possible to have both _auto_ downcasting and new method binding to work in Go? -- regards, Nurahmadie -- -- 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%2BcQEWFJd0M9hp_dVDEXDtCHeKJVSi5sQY0dSqO9bn-BDBykeA%40mail.gmail.com.