How to understand the two named types are identical in golang

Type identity rules state that:

Two named types are identical if their type names originate in the same TypeSpec

I do not quite understand how two types of names arise in the same TypeSpec. Can you explain this or show me an example?

+4
source share
2 answers

Only one type name can come from TypeSpec. A question. So

type Foo int64
var x Foo
var y Foo

then both Foocome from the same TypeSpec, so they are identical to Foos.

However, if you have two different files (in different packages):

a.go:

type Foo int64
var x Foo

b.go:

type Foo int64
var y Foo

Foo . , , TypeSpec. , x y (, , x = y ).

+7

Two named types are identical if their type names originate in the same TypeSpec

, , Go. Go, originate in the same TypeSpec . , .

, : byte uint8; int32,

.

: Go 1.9 : type alias/alias declarations. , . Go 1.9

0

All Articles