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) *NamedParameters & Attributes
| Name | Type | Description |
|---|---|---|
| obj | *TypeName | Object associated with the type or scope. |
| underlying | Type | Underlying type of the defined type. |
| methods | []*Func | Method 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)}