Skip to content
Learn Netverks

Lesson

Step 33/36 92% through track

reflect-intro

Reflection intro

Last reviewed Jun 1, 2026 Content v20260601
Track mode
server_compiled
Means
Compiled runner
Reading
~1 min
Level
advanced

This lesson

An orientation to the Go track—how the compiled playground works, core vocabulary, and what you will practice next.

You need a clear map of the Go track so packages, interfaces, goroutines, and go mod do not feel like magic.

You will apply Reflection intro in contexts like: Kubernetes ecosystem tools, cloud APIs, and CLI utilities.

Write Go in main.go with package main and func main(), click Run on server—the dev runner runs go run main.go; use fmt.Println for output (requires Go toolchain; LEARNING_RUNNER_ENABLED=true). Also read the interview prep blocks.

After Python, Java, or C—Go is small but strict; prior imperative experience makes interfaces and pointers easier.

The reflect package inspects types and values at runtime—powerful but slower and less clear than generics or code generation. Used in JSON, ORM-like tools, and dependency injection frameworks.

Basic reflect

v := reflect.ValueOf(x)
t := reflect.TypeOf(x)
fmt.Println(t.Kind(), v.Interface())

Values must be addressable to mutate via reflection. Prefer compile-time types when possible—reflection is last resort.

Important interview questions and answers

  1. Q: When avoid reflection?
    A: Hot paths, simple APIs, when generics or interfaces suffice.
  2. Q: reflect vs generics?
    A: Generics give compile-time safety; reflection trades performance for flexibility.

Self-check

  1. Which package provides TypeOf and ValueOf?
  2. Why is reflection slower?

Tip: Prefer generics or code generation over reflection in hot paths—reflection is for frameworks and one-off tooling.

Interview prep

When avoid reflection?

Hot paths and simple APIs—prefer compile-time types or generics.

reflect performance?

Slower and less clear—runtime type inspection has overhead.

Interview tip Lesson completion confidence

Can you explain this lesson in 30 seconds without reading notes?

Not saved yet.

Playground

Runs on the configured server runner (dev: npm run runner with LEARNING_RUNNER_ENABLED=true). Output appears below the editor.

Check yourself

Multiple choice — immediate feedback.

Discussion

Past discussion is visible to everyone. Only logged-in users can post comments and replies.

Starter discussion topics

  • reflect.TypeOf?
  • Avoid reflect when?

Sign up or log in to post comments and sync lesson progress across devices.

No discussion yet. Be the first to ask a question.

Jump