aboutsummaryrefslogtreecommitdiff
path: root/src/reflect/example_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/reflect/example_test.go')
-rw-r--r--src/reflect/example_test.go18
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