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
value.(string)crashes with a run-time error if the value does not contain a string. Use the "comma, ok" idiom to test, safely, whether the value is a string.- To discover the dynamic type of an interface variable, a type switch uses type assertion syntax with the keyword
typeinside the parentheses.
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
- id: C1 claim: Interfaces specify the behavior of an object. source: S1 evidence: "Interfaces in Go provide a way to specify the behavior of an object"
- id: C2 claim: A type need not declare that it implements an interface. source: S1 evidence: "a type need not declare explicitly that it implements an interface"
- id: C3 claim: Use the comma, ok idiom to test a type assertion safely. source: S1 evidence: "use the \"comma, ok\" idiom to test, safely, whether the value is a string"
- id: C4 claim: An interface type defines a type set. source: S2 evidence: "An interface type defines a type set ."
Sources
- [S1] Effective Go. Go docs. https://go.dev/doc/effective_go . License: CC-BY-4.0. Accessed 2026-11-18.
- [S2] The Go Programming Language Specification. Go docs (reference). https://go.dev/ref/spec . License: CC-BY-4.0. Accessed 2026-11-18.
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
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.},
}
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.