diff options
| author | Don Byington <don@dbyington.com> | 2018-10-03 21:54:54 +0000 |
|---|---|---|
| committer | Ian Lance Taylor <iant@golang.org> | 2018-10-03 22:38:53 +0000 |
| commit | d16e4d34fc24c2c4ad6d4965edb17204ca5e1c67 (patch) | |
| tree | a9ebf7d09fa724e09d6ed4bdcbe8d5e7e4b7f885 /src | |
| parent | 85c9c85955fc5373fa63267ad69e4b1a72bb5f44 (diff) | |
| download | go-d16e4d34fc24c2c4ad6d4965edb17204ca5e1c67.tar.xz | |
reflect: add an example for Kind
Fixes #27990
Change-Id: I0f09fc6f68cec770b1c26eed2315afbf6bf6cd4d
GitHub-Last-Rev: 8486e6d5019c6c21b10e5fcf10a2727cf2705174
GitHub-Pull-Request: golang/go#27991
Reviewed-on: https://go-review.googlesource.com/c/139417
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Diffstat (limited to 'src')
| -rw-r--r-- | src/reflect/example_test.go | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/reflect/example_test.go b/src/reflect/example_test.go index f959b95846..23c08e4950 100644 --- a/src/reflect/example_test.go +++ b/src/reflect/example_test.go @@ -13,6 +13,24 @@ import ( "reflect" ) +func ExampleKind() { + for _, v := range []interface{}{"hi", 42, func() {}} { + switch v := reflect.ValueOf(v); v.Kind() { + case reflect.String: + fmt.Println(v.String()) + case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: + fmt.Println(v.Int()) + default: + fmt.Printf("unhandled kind %s", v.Kind()) + } + } + + // Output: + // hi + // 42 + // unhandled kind func +} + func ExampleMakeFunc() { // swap is the implementation passed to MakeFunc. // It must work in terms of reflect.Values so that it is possible |
