[Journey with golang] 6. Reflection

In computer science, the reflection means can access the computer program at run time, a capability to modify themselves and detecting a state or behavior. In layman's terms, reflecting the program is able to dynamically check their status at run time, and allowed to modify their own behavior.

Golang reflective base is to compile and runtime type information in the appropriate data structure stored in the executable program. reflect the standard library provides a set of knowledge golang provide access to the user interface language, language designers to consider implementation is reflected in the design of the language. This article explains the usage reflect the standard library. golang reflection based on the type of system on the go, and the interface has a close relationship.

go subtly reflected by the interface to the data structure example of the conversion required, the first instance to pass inside the empty interface, is actually an instance of the type to an interface representation data structure may eFace, reflected on the conversion data structure to access and manipulate the instances of types and values. In the learning process, we know that the interface to the interface {} Example pass type, the compiler converts an internal data structure of the relevant type is automatically created. If you do not do this design, it is possible language implementor would go on to design a type of data structure to support reflection.

// to be continued

Guess you like

Origin www.cnblogs.com/JHSeng/p/12233493.html