Go

Reflection

reflect package, type inspection, value manipulation, struct tags, use cases, performance

20 면접 질문·
Senior
1

What is the reflect package in Go?

답변

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.

2

How to get the type of a variable with the reflect package?

답변

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

3

What is the difference between reflect.Type and reflect.Value?

답변

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

4

How to modify a variable's value via reflection?

5

What is a reflect.Kind?

+17 면접 질문

다음 면접을 위해 Go을 마스터하세요

모든 질문, flashcards, 기술 테스트, 코드 리뷰 연습, 면접 시뮬레이터에 접근하세요.

무료로 시작하기