Converting data types and interface casting

Go is typically very flexible when used to convert data from one type to another. A type may inherit another type, as follows:

type A int

We can always cast back to the type we inherited, as follows:

var a A = 1
fmt.Println(int(a))

There are also convenience functions for converting between numbers using casting, between strings and other types using fmt.Sprint and strconv, and between interfaces and types using reflection. This recipe will explore some of these basic conversions, which will be used throughout this book.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.17.64.47