Go Type Switch: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
|||
Line 1: | Line 1: | ||
=Internal= | =Internal= | ||
* [[Go_Interfaces#Type_Switch|Go Interfaces]] | * [[Go_Interfaces#Type_Switch|Go Interfaces]] | ||
* [[ | * [[Go_Type_Assertion#Overview|Type Assertion]] | ||
=Overview= | =Overview= |
Revision as of 16:32, 14 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)
}