← BYTES
Go·Starter·Ref: 10.1.14

What does the type `interface{}` (or its modern alias `any`) mean?

Have a question about this video? Mention reference 10.1.14 when you contact us.

a.A syntax error -- interfaces must always declare at least one method
b.A special numeric type with unlimited precision
c.A type that can hold a value of literally any type at all, since it requires zero methods to satisfy it
d.A type exclusively used for error values
interface{} (written as any since Go 1.18) is the empty interface -- since it has no method requirements whatsoever, every single type in Go automatically satisfies it, making it the type used when a variable genuinely needs to hold a value of any type, at the cost of losing compile-time type information until a type assertion or switch is used to recover it.

Find this on YouTube & Instagram

Every BYTES video is tagged with its reference number and topic — search any of these on YouTube or Instagram to find this one:

#BYTES#BYTES10114#Go