使用conversion将myint
转换为int
:
package main
import "fmt"
type myint int
func main() {
foo := myint(1) // foo has type myint
i := int(foo) // use type conversion to convert myint to int
fmt.Println(i)
}
类型myint
不是int的别名.这是一种不同的类型.例如,表达式myint(0) + int(1)
不编译,因为操作数是不同类型的.GO中有两个内置类型别名,rune和byte.应用程序不能定义自己的别名.