```go
type Test string
const (
M Test = "M"
N Test = "N"
)
var Test k = M
```
** 这样用的意义是什么,而不使用下面这种 **
```go
var Test string= "M"
```
以context包为例
https://golang.org/pkg/context/
The provided key must be comparable and should not be of type string or any other built-in type to avoid collisions between packages using context. Users of WithValue should define their own types for keys. To avoid allocating when assigning to an interface{}, context keys often have concrete type struct{}. Alternatively, exported context key variables' static type should be a pointer or interface.
总的来说
作为key判断的话
"key"和Test("key") 是不同的值
#3
更多评论