Expression
Type assertions
An interface assertion tests the dynamic concrete type or implementation of a requested interface. Single-result assertions panic on failure; comma-ok assertions return a zero value and false. The operand cannot be a type parameter. Example output: 'tea true 0 false'.
Formal Syntax & Structure
go syntaxgo
value.(T)Working Example
Example Snippetgo
package main
import "fmt"
func main() { var v any = "tea" text, ok := v.(string) n, found := v.(int) fmt.Println(text, ok, n, found)}