Go Type Switch: Difference between revisions
Jump to navigation
Jump to search
Line 1: | Line 1: | ||
=Internal= | =Internal= | ||
* [[Go_Interfaces#Type_Switch|Go Interfaces]] | |||
* [[Go_Type_Assertions#Overview|Type Assertion]] | * [[Go_Type_Assertions#Overview|Type Assertion]] | ||
Revision as of 23:32, 13 August 2024
Internal
Overview
A type switch is a new control structure introduced by Go.
Type assertion with switch
:
var i SomeInterface
i = TypeA{"A"}
switch v := i.(type) {
case TypeA:
fmt.Printf("TypeA: %v\n", v)
case TypeB:
fmt.Printf("TypeB: %v\n", v)
}