Standard library / go/types

go/types.NewNamed()

Creates a defined type from a type-name object and a non-named underlying type. Expected stdout: 'Count int true\n'.

Formal Syntax & Structure

go syntaxgo
func NewNamed(obj *TypeName, underlying Type, methods []*Func) *Named

Parameters & Attributes

NameTypeDescription
obj*TypeNameObject associated with the type or scope.
underlyingTypeUnderlying type of the defined type.
methods[]*FuncMethod objects to attach.

Return Value

*Named

Creates a defined type from a type-name object and a non-named underlying type.

Working Example

Example Snippetgo
package main
import (  "fmt"  "go/types")
func main() {  o := types.NewTypeName(0, nil, "Count", nil)  t := types.NewNamed(o, types.Typ[types.Int], nil)  fmt.Println(t, t.Underlying(), o.Type() == t)}
Go Reference