Reflection is an advanced Go feature that allows you to dynamically learn the type of an arbitrary object, as well as information about its structure. Go offers the reflect package for working with reflection. What you should remember is that you will most likely not need to use reflection in every Go program. So, the first two questions are: why is reflection necessary and when should you use it?
Reflection is necessary for the implementation of packages such as fmt, text/template, and html/template. In the fmt package, reflection saves you from having to explicitly deal with every data type that exists. However, even if you had the patience to write code to work with every data type that you know of, you would still not be able to work with all possible types! In this case, reflection makes it possible for the methods of the fmt package to find the structure and to...