Standard library / go/types
go/types.NewInterfaceType()
Constructs an interface from explicit methods and embedded types. Complete it before using its method set. Expected stdout: 'false true\n'.
Formal Syntax & Structure
go syntaxgo
func NewInterfaceType(methods []*Func, embeddeds []Type) *InterfaceParameters & Attributes
| Name | Type | Description |
|---|---|---|
| methods | []*Func | Method objects to attach. |
| embeddeds | []Type | Input to the operation as described above. |
Return Value
*Interface
Constructs an interface from explicit methods and embedded types.
Working Example
Example Snippetgo
package main
import ( "fmt" "go/types")
func union() *types.Union { return types.NewUnion([]*types.Term{term(), types.NewTerm(false, types.Typ[types.String])})}
func term() *types.Term { return types.NewTerm(true, types.Typ[types.Int]) }
func main() { i := types.NewInterfaceType(nil, []types.Type{union()}).Complete() fmt.Println(i.IsMethodSet(), types.Satisfies(types.Typ[types.Int], i))}