---
source: https://iinventedlight.com/library/notes/go-interfaces.md
title: "Go interfaces are satisfied implicitly by implementing their methods"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "CC-BY-4.0 (Go docs); CC-BY-4.0 (Go docs (reference)); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "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."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-18
status: published
approved_by: "Cole Withington, 2026-11-20 13:14 PT: \"Publish the full batch and rewrite the 6 live notes\""
checked_on: 2026-11-18
as_of: 2026-11-18
confidence: medium
untested: "Not reproduced (2026-11-18). Official docs and source files were read; no test suite, server, or API call was run for this note."
category: coding-references
topic_area: "code-systems: Go interfaces"
tags: [go, interfaces, type-assertion, type-switch, implicit]
client: Librarian
sources:
  - id: S1
    title: "Effective Go"
    publisher: Go docs
    url: https://go.dev/doc/effective_go
    accessed: 2026-11-18
    license: "CC-BY-4.0"
  - id: S2
    title: "The Go Programming Language Specification"
    publisher: Go docs (reference)
    url: https://go.dev/ref/spec
    accessed: 2026-11-18
    license: "CC-BY-4.0"
---
# 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`.

```go
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 `type` inside 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

- [go-generics](https://iinventedlight.com/library/notes/go-generics/)
- [go-error-handling](https://iinventedlight.com/library/notes/go-error-handling/)
- [go-testing](https://iinventedlight.com/library/notes/go-testing/)

## 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.

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
