Skip to content

Commit d16e4d3

Browse files
dbyingtonianlancetaylor
authored andcommitted
reflect: add an example for Kind
Fixes #27990 Change-Id: I0f09fc6f68cec770b1c26eed2315afbf6bf6cd4d GitHub-Last-Rev: 8486e6d GitHub-Pull-Request: #27991 Reviewed-on: https://go-review.googlesource.com/c/139417 Run-TryBot: Ian Lance Taylor <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]>
1 parent 85c9c85 commit d16e4d3

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/reflect/example_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,24 @@ import (
1313
"reflect"
1414
)
1515

16+
func ExampleKind() {
17+
for _, v := range []interface{}{"hi", 42, func() {}} {
18+
switch v := reflect.ValueOf(v); v.Kind() {
19+
case reflect.String:
20+
fmt.Println(v.String())
21+
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
22+
fmt.Println(v.Int())
23+
default:
24+
fmt.Printf("unhandled kind %s", v.Kind())
25+
}
26+
}
27+
28+
// Output:
29+
// hi
30+
// 42
31+
// unhandled kind func
32+
}
33+
1634
func ExampleMakeFunc() {
1735
// swap is the implementation passed to MakeFunc.
1836
// It must work in terms of reflect.Values so that it is possible

0 commit comments

Comments
 (0)