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 개발자처럼 생각하는 방법
404
러닝 Go
stringSliceType
을 위한 것은
nil
은 슬라이스를 위한 유효한 값이기 때문에 조금 더 간단하
다. 우리가 해야 하는 모든 것은
nil
[]
string
으로 타입 변환하고 그것을
reflect
.
Type
로 넘기는 것이다.
이제 이런 타입을 가지고
reflect
.
New
reflect
.
MakeSlice
사용법을 알아 볼 것이다.
ssv := reflect.MakeSlice(stringSliceType, 0, 10)
sv := reflect.New(stringType).Elem()
sv.SetString(“hello”)
ssv = reflect.Append(ssv, sv)
ss := ssv.Interface().([]string)
fmt.Println(ss) // prints [hello]
해당 코드는
Go
플레이그라운드
3
에서 직접 실행해 볼 수 있다.
14.1.3
인터페이스의 값이
nil
인지 확인하기 위해 리플렉션 사용
7
.
9
절 ‘인터페이스와
nil
’에서 언급한 것처럼, 구체 타입의
nil
변수는 페이스 타입의 변수에
할당되면 인터페이스 타입의 변수는
nil
이 아니다. 이는 인터페이스 변수와 연결된 타입이 있
기 때문이다. 인터페이스와 연관된 값이
nil
인지 확인하려고 한다면,
IsValid
IsNil
메서
드를 사용하는 리플렉션으로 할 수 ...
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