typeover
curriculum

Curriculum Errors & packaging Type assertions & type switches exercise 6 · fill-line

Type assertions & type switches


About this theme

v.(T) asserts that an interface value v is actually of type T. Panics if wrong. Use the comma-ok form to check first: if t, ok := v.(T); ok { ... }. For multi-branch checks, switch v := i.(type) dispatches on dynamic type.