【Go】Type assertion

go type assertions

Type assertions provide a way to access the underlying concrete values of an interface value

v: = i.(T)

This statement asserts that the interface value i holds the concrete type T and assigns the value of its underlying type T to the variable t

If i does not hold a value of type T, the statement triggers an exception

In order to judge whether the interface value holds a certain type, the type assertion can return two values

v, ok: = i.(T)

If i holds type T, v is its underlying value and ok is true
Otherwise ok is false

Persist in original technology sharing, your support will encourage me to continue to create!