Golang中type有没有等号的区别

所谓type有没有等号“=”,用Golang语言来说,看起来这样的:

type myInt int
type myIntAilas = int

即使不严格来说,两者也是不一样的... 来看个例子:

package main

import (
	"fmt"
	"reflect"
)

type myInt int
type myIntAilas = int

func main() {
	var t1 myInt
	var t2 myIntAilas

	//fmt.Printf("t1: %T", t1)
	//fmt.Printf("t2: %T", t2)
	fmt.Println(reflect.TypeOf(t1))
	fmt.Println(reflect.TypeOf(t2))
}

输出:

type of t1:  main.myInt
type of t2:  int

看出来了吧?没有等号“=”的,穿了个马甲... 学名叫Alias,假名。

"春节期间,Tony、Kevin回到了阔别已久的家乡,又变成了 狗剩子、二蛋“。

 

 

 

 

你可能感兴趣的:(Go)