Created
December 12, 2017 18:04
-
-
Save jonbodner/bf8a25ffdca371755ddce7c01983c8f5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func main() { | |
// declaring these vars, so I can make a reflect.Type | |
intSlice := make([]int, 0) | |
mapStringInt := make(map[string]int) | |
// here are the reflect.Types | |
sliceType := reflect.TypeOf(intSlice) | |
mapType := reflect.TypeOf(mapStringInt) | |
// and here are the new values that we are making | |
intSliceReflect := reflect.MakeSlice(sliceType, 0, 0) | |
mapReflect := reflect.MakeMap(mapType) | |
// and here we are using them | |
v := 10 | |
rv := reflect.ValueOf(v) | |
intSliceReflect = reflect.Append(intSliceReflect, rv) | |
intSlice2 := intSliceReflect.Interface().([]int) | |
fmt.Println(intSlice2) | |
k := "hello" | |
rk := reflect.ValueOf(k) | |
mapReflect.SetMapIndex(rk, rv) | |
mapStringInt2 := mapReflect.Interface().(map[string]int) | |
fmt.Println(mapStringInt2) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment