Standard library / go/types

go/types.Implements()

Reports whether a type implements an interface. Use Satisfies for constraint satisfaction. Expected stdout: 'true\n'.

Formal Syntax & Structure

go syntaxgo
func Implements(V Type, T *Interface) bool

Parameters & Attributes

NameTypeDescription
VTypeSource or candidate type.
T*InterfaceDestination type or interface, or type to inspect.

Return Value

bool

Reports whether a type implements an interface.

Working Example

Example Snippetgo
package main
import (  "fmt"  "go/types")
func main() {  fmt.Println(types.Implements(types.Typ[types.Int], types.NewInterfaceType(nil, nil).Complete()))}
Go Reference