The Empty Interface

Let’s learn about the empty interface in Go.

What is the empty interface?

As mentioned before, the empty interface is defined as just interface{} and is already implemented by all data types. Thus, variables of any data type can be put in the place of a parameter of the empty interface data type. Therefore, a function with an interface{} parameter can accept variables of any data type in this place. However, if we intend to work with interface{} function parameters without examining their data type inside the function, we should process them with statements that work on all data types; otherwise, our code may crash or misbehave.

Get hands-on with 1400+ tech skills courses.