
Reflection
reflect package, type inspection, value manipulation, struct tags, use cases, performance
1What is the reflect package in Go?
What is the reflect package in Go?
Antwort
The reflect package allows inspecting and manipulating types and values at runtime. It is used to implement generic libraries (JSON marshaling, ORM), but its direct use in application code is discouraged as it sacrifices type safety and performance.
2How to get the type of a variable with the reflect package?
How to get the type of a variable with the reflect package?
Antwort
The reflect.TypeOf() function returns a reflect.Type representing the dynamic type of the interface passed as argument. If the variable is nil, reflect.TypeOf() returns nil. Using .Kind() on the returned Type allows getting the type category (int, string, struct, etc.).
3What is the difference between reflect.Type and reflect.Value?
What is the difference between reflect.Type and reflect.Value?
Antwort
reflect.Type represents type metadata (name, kind, methods, fields) and is obtained via reflect.TypeOf(). reflect.Value represents the concrete value and allows reading or modifying it via reflect.ValueOf(). Both are complementary: Type describes 'what' and Value contains 'the data'.
How to modify a variable's value via reflection?
What is a reflect.Kind?
+17 Interview-Fragen
Weitere Go-Interviewthemen
Go Basics
Go Data Structures
Go Interfaces
Error Handling
Goroutines Basics
Channels
Go Modules
HTTP Server
HTTP Client
JSON Encoding
database/sql
Context Package
Testing
Concurrency Patterns
Sync Primitives
Go Web Frameworks
REST API Design
gRPC
Memory Management
Performance Optimization
Generics
Go Design Patterns
Microservices
Security & Authentication
Docker & Containerization
Kubernetes Basics
Advanced Go
CLI Development
Meistere Go für dein nächstes Interview
Zugang zu allen Fragen, Flashcards, technischen Tests, Code-Review-Übungen und Interview-Simulatoren.
Kostenlos starten