General interfaces
April 19, 2023
Today we’re venturing into generics territory.
General interfaces
In their most general form, an interface element may also be an arbitrary type term
T
, or a term of the form~T
specifying the underlying typeT
, or a union of termst1|t<sub<>2|…|tn
.
We haven’t actually learned about type terms yet–they’re coming in a few weeks. But for now, the TL;DR is that they let us specify a type by its name, rather than by its method(s).
We see some examples, just a bit later in the spec:
// An interface representing only the type int. interface { int } // An interface representing all types with underlying type int. interface { ~int }
We’ll talk in more detail about the ~
prefix shortly.
Quotes from The Go Programming Language Specification Version of December 15, 2022