TypeOf in Go

Posted by GoDoc
Public (Editable by Users)

TypeOf returns the reflection Type that represents the dynamic type of i. If i is a nil interface value, TypeOf returns nil.

Go
Edit
package main

import (
    "fmt"
    "io"
    "os"
    "reflect"
)

func main() {
    // 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))
}