Skip to main content
Definition Website Computer and Technology

Reflection

Subject: Computer and Technology noun /rɪˈflɛk.ʃən/ 1 definition

  1. Definition (noun)

    Entry #260 · Updated

    Reflection is a metaprogramming capability that allows a program to inspect, query, and manipulate its own structure, type metadata, and behavior. Instead of relying solely on fixed symbol references, reflective code treats types, fields, methods, and attributes as programmatic data—most commonly evaluated at runtime, though some languages support it at compile time. Because dynamic reflection trades compile-time type guarantees and direct dispatch speed for late-binding flexibility, it is primarily bounded to infrastructure layers such as serialization, dependency injection, object-relational mapping, and testing frameworks.

    Common Forms

    • Introspection: Read-only inspection of a program's own types, fields, methods, and custom attributes at runtime, powering serializers, validators, and developer tooling.

    • Dynamic Invocation: Looking up and executing constructors, methods, or field accessors by name at runtime, enabling plugin architectures, scripting bridges, and dependency injection.

    • Behavioral Intercession: Intercepting and altering execution semantics—such as method dispatch or property access—via dynamic proxies, metaclasses, or bytecode weaving.

    • Static Reflection: Inspecting type metadata at compile time to generate specialized, type-safe code without shipping runtime metadata tables or paying dynamic dispatch overhead.

    Example

    When a Go service passes a User struct to json.Marshal, the encoder uses runtime reflection to inspect the struct's exported fields and json tags without requiring custom boilerplate. It reads each field's value dynamically and maps FirstName to the "first_name" JSON key based on the metadata attached to the type definition.