← All notes

Go interfaces are satisfied implicitly by implementing their methods

Answer: Interfaces in Go specify the behavior of an object; whatever can do this can be used here. A type need not declare explicitly that it implements an interface; it implements the interface just by implementing the interface's methods.

Small interfaces

In Go code, interfaces with only one or two methods are common; their name is usually derived from the method, such as io.Writer.

type Stringer interface { String() string }

str, ok := value.(string)     // comma, ok
switch v := value.(type) {     // type switch
case string:
    fmt.Println("string", v)
case Stringer:
    fmt.Println(v.String())
}

var _ json.Marshaler = (*RawMessage)(nil) // compile-time check

Type assertions and switches

Spec view

An interface type defines a type set, and a variable of that interface type can store a value of any type in the set. Any given type may implement several distinct interfaces, and all types implement the empty interface.

See also

Claims

Sources

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Go docs, Effective Go; Go docs (reference), The Go Programming Language Specification. CC-BY-4.0 (https://go.dev/copyright). Copyright The Go Authors. Text was condensed and changed from the originals.

License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Go docs, Effective Go; Go docs (reference), The Go Programming Language Specification. CC-BY-4.0 (https://go.dev/copyright). Copyright The Go Authors.

Cite this

Permanent ID: iil:note:220hkd0a

iinventedlight. 2026. "Go interfaces are satisfied implicitly by implementing their methods." iinventedlight Library, iil:note:220hkd0a, version of 2026-11-18. https://iinventedlight.com/library/notes/go-interfaces/. License: CC-BY-4.0.

@misc{iil_note_220hkd0a,
  author = {{iinventedlight}},
  title = {{Go interfaces are satisfied implicitly by implementing their methods}},
  howpublished = {iinventedlight Library},
  year = {2026},
  date = {2026-11-18},
  url = {https://iinventedlight.com/library/notes/go-interfaces/},
  note = {Permanent ID iil:note:220hkd0a. License: CC-BY-4.0.},
}

Markdown

Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).

For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/go-interfaces.md.