empty interface
The interface with no methods, spelled any or interface{}, which every Go type satisfies.
In more detail
Use it only at true boundaries, such as decoded data of unknown shape or print arguments. A value of type any hides its real type from the compiler, so you must assert back to a concrete type before doing anything useful. Typed structs keep compiler checks and are easier to reason about.
Example
func show(value any) {}Related terms
- interface — A named set of member signatures that a type promises to implement, with no state of its own.
- type assertion — An expression such as value.(string) that gets the concrete value out of an interface, if it really holds that type.
- type switch — A switch statement written switch v := value.(type) that picks a branch by the concrete type inside an interface value.
- interface value — A value held in an interface variable, which carries two parts: the concrete type it really is and the value itself.
Taught in
- Variables, Typing, and Zero Values — Concurrent Systems Programming with Go
- Interfaces and Why They Are Implicit — Concurrent Systems Programming with Go
- Type Assertions and the Empty Interface — Concurrent Systems Programming with Go