Considering the fact that go is statically typed language, What is the meaning of a dynamic type of some value ?
The 'dynamic type' of a variable is important when handling interface values. Dynamic types are defined as follows (source):
The static type (or just type) of a variable is the type defined by its declaration. Variables of interface type also have a distinct dynamic type, which is the actual type of the value stored in the variable at run time. The dynamic type may vary during execution but is always assignable to the static type of the interface variable. For non-interface types, the dynamic type is always the static type.
Consider this example:
var someValue interface{} = 2
The static type of someValue
is interface{}
but the dynamic type is int
and may very
well change in the future. Example:
var someValue interface{} = 2
someValue = "foo"
In the example above the dynamic type of someValue
changed from int
to string
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With