summaryrefslogtreecommitdiff
path: root/libgo/go/reflect/example_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'libgo/go/reflect/example_test.go')
-rw-r--r--libgo/go/reflect/example_test.go15
1 files changed, 15 insertions, 0 deletions
diff --git a/libgo/go/reflect/example_test.go b/libgo/go/reflect/example_test.go
index cca28eeece8..8ebf9765b8d 100644
--- a/libgo/go/reflect/example_test.go
+++ b/libgo/go/reflect/example_test.go
@@ -6,6 +6,8 @@ package reflect_test
import (
"fmt"
+ "io"
+ "os"
"reflect"
)
@@ -64,3 +66,16 @@ func ExampleStructTag() {
// Output:
// blue gopher
}
+
+func ExampleTypeOf() {
+ // As interface types are only used for static typing, a
+ // common idiom to find the reflection Type for an interface
+ // type Foo is to use a *Foo value.
+ writerType := reflect.TypeOf((*io.Writer)(nil)).Elem()
+
+ fileType := reflect.TypeOf((*os.File)(nil))
+ fmt.Println(fileType.Implements(writerType))
+
+ // Output:
+ // true
+}