Go type alias type definition difference

Type alias, and custom type difference

Custom Types

// custom type is to define a new type
 // will MyInt defined as int type 
of the type MyInt int

Type alias

// type alias provisions: TypeAlias only Type an alias, in essence, TypeAlias and Type are the same type. 
= typeAlias of the type Type 
of the type byte = uint8 
of the type Rune = Int32

the difference

Type alias type definition is only one difference between the surface of the equal sign

// type definition 
type NewInt int 

// type alias 
type MyInt = int 

FUNC main () { 
    var A NewInt
     var B MyInt 
    
    fmt.Printf ( " type of A: T% \ n- " , A) // type of A: main .NewInt 
    fmt.Printf ( " type of B:% T \ n- " , B) // type of B: int 
} 
// difference
// display a result of the type main.NewIntshowing the main package defined NewInttype. b type is int. MyIntType in the code will only exist when there is not compiled MyInttypes.

 

Guess you like

Origin www.cnblogs.com/Paul-watermelon/p/11100854.html