Skip to Content
러닝 Go : Go 개발자처럼 생각하는 방법
book

러닝 Go : Go 개발자처럼 생각하는 방법

by 존 보드너, 윤대석
February 2022
Beginner to intermediate
452 pages
10h 48m
Korean
Hanbit Media, Inc.
Content preview from 러닝 Go : Go 개발자처럼 생각하는 방법
403
14
Reflect, Unsafe, Cgo
14.1.2
새로운 값 만들기
리플렉션을 가장 잘 사용하는 방법을 보기 전에 값을 생성하는 방법을 먼저 다루어 봐야한다.
reflect
.
New
함수는
new
함수의 리플렉션 버전이다. 그것은
reflect
.
Type
을 받고 지정된
타입의
reflect
.
Value
를 가리키는 포인터인
reflect
.
Value
를 반환한다. 포인터이기 때문
에 수정이 가능하고
Interface
메서드를 사용하여 변수로 변경된 값을 할당할 수도 있다.
reflect
.
New
가 스칼라 타입을 가리키는 포인터를 생성하는 것과 같이
make
키워드와 동일한
일을 하기 위해 다음과 같은 함수로 리플렉션을 사용할 수 있다.
func MakeChan(typ Type, buffer int) Value
func MakeMap(typ Type) Value
func MakeMapWithSize(typ Type, n int) Value
func MakeSlice(typ Type, len, cap int) Value
이 함수들은 각각 포함된 타입이 아닌 복합 타입을 나타내는
reflect
.
Type
을 받는다.
reflect
.
Type
을 구성할 때 값에서부터 시작해야 한다. 하지만 유용한 값이 없는 경우
reflect
.
Type
을 나타내는 변수를 생성할 수 있는
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

효율적인 리눅스 명령어 사용의 기술

효율적인 리눅스 명령어 사용의 기술

Daniel J Barrett

Publisher Resources

ISBN: 9791162245309