Standard library / go/types
go/types.Named.SetUnderlying()
Sets a defined type’s underlying type. Use only while constructing a type, before sharing it. Expected stdout: 'int\n'.
Formal Syntax & Structure
go syntaxgo
func (t *Named) SetUnderlying(underlying Type)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| underlying | Type | Underlying type of the defined type. |
Working Example
Example Snippetgo
package main
import ( "fmt" "go/types")
func main() { v := types.NewNamed(types.NewTypeName(0, nil, "N", nil), nil, nil) v.SetUnderlying(types.Typ[types.Int]) fmt.Println(v.Underlying())}