Go reflect: run-time reflection for types and values
Answer: The package implements run-time reflection, allowing a program to manipulate objects with arbitrary types.
Types and values
Start from an interface value and call TypeOf to recover a Type for the dynamic type.
ValueOf wraps the run-time data in a Value.
Zero takes a Type and returns a Value representing a zero value.
Limits of the API
Many methods are legal only for some kinds of types.
Kind tells you which kind you have before you call a kind-specific method.
A method used on the wrong kind panics at run time.
Two Type values are equal if they represent identical types.
See also
Claims
- id: C1 claim: The package implements run-time reflection for objects with arbitrary types. source: S1 evidence: "implements run-time reflection, allowing a program to manipulate objects"
- id: C2 claim: ValueOf returns a Value representing the run-time data. source: S1 evidence: "ValueOf returns a Value representing the run-time data"
- id: C3 claim: A method used on the wrong kind panics at run time. source: S2 evidence: "inappropriate to the kind of type causes a run-time panic"
- id: C4 claim: Two Type values are equal if they represent identical types. source: S2 evidence: "Two Type values are equal if they represent identical types"
Sources
- [S1] reflect package reference. The Go Authors. https://pkg.go.dev/reflect . License: BSD-3-Clause. Accessed 2026-11-24.
- [S2] reflect type.go source. The Go Authors. https://go.dev/src/reflect/type.go . License: BSD-3-Clause. Accessed 2026-11-24.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: The Go Authors, reflect package reference; The Go Authors, reflect type.go source. BSD-3-Clause (https://go.dev/LICENSE). Copyright The Go Authors. Text was condensed and changed from the originals.
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: The Go Authors, reflect package reference; The Go Authors, reflect type.go source. BSD-3-Clause (https://go.dev/LICENSE). Copyright The Go Authors.
Cite this
iinventedlight. 2026. "Go reflect: run-time reflection for types and values." iinventedlight Library, iil:note:afc90dvc, version of 2026-11-24. https://iinventedlight.com/library/notes/go-reflect/. License: CC-BY-4.0.
@misc{iil_note_afc90dvc,
author = {{iinventedlight}},
title = {{Go reflect: run-time reflection for types and values}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-24},
url = {https://iinventedlight.com/library/notes/go-reflect/},
note = {Permanent ID iil:note:afc90dvc. 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).
Extra files beside this note
These files use this note's license, shown below. Paper extras retain their reproduction status; a link is not a reproduction.
- go-reflect.schema.json (schema; CC-BY-4.0)
- go-reflect.table.json (table; CC-BY-4.0)
For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/go-reflect.md.