What Is the Empty Interface (interface{} and any) in Go

The empty interface interface{} (or any) holds values of any type by having no required methods.

The empty interface interface{} (or any in Go 1.18+) is a type that holds values of any type because it has no methods to satisfy. Use it when you need a variable to store data of unknown or varying types, such as in generic collections before generics were available.

var v interface{} = 42
v = "hello"
v = []int{1, 2, 3}

// Go 1.18+ alias
var a any = v