Every type has a method set

June 8, 2023

Method sets

The method set of a type determines the methods that can be called on an operand of that type. Every type has a (possibly empty) method set associated with it.

Wait right there.

That bears repeating

Every type has a (possibly empty) method set

Let that sink in.

Every type has a method set.

This surprises many newcomers, as in many langauges, we’re accustomed to thinking of only “objects” having methods. And many (somewhat erroneously) translate this to the idea that “in Go, we use structs as objects, so only structs can have methods.”

But in Go, we can define methods on any type, not just structs.

Quotes from The Go Programming Language Specification Version of December 15, 2022


Share this

Direct to your inbox, daily. I respect your privacy .

Unsure? Browse the archive .