On Tuesday, 13 August 2019 08:10:56 UTC+2, Sathish VJ wrote: > > So doing *type X Y* is just a type declaration then? >
Yes, of course. It declares a new named type X, the underlying type is Y which can be some predeclared type like int, some other named declared type (like MyFooType) or a "type literal" (a term I made up) like struct{X,Y float64; T string} or map[string]bool or chan time.Time . The main reason to declare a new type like type NewType SomeExistingType is that NewType starts of with an empty method set and you can implement totally different methods on it or even implement the methods with the same name but with different signatures and/or different semantics. Type aliases are necessary e.g. during refactoring large code bases or to provide a certain compatibility. Do not use them in "regular" code as they do not provide any value but make reading the code harder. You might want to read more about "embedding" one type into a struct type: Grep the Spec for "embedded field". Embedding allows to have a new type with potentially different method set but reuse methods of the embedded type. V. -- 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/c2b3a8b9-fef1-4fc5-b605-10f1fb67eebf%40googlegroups.com.