有以下代码
var v interface{}
v = rune(1)
switch v.(type) {
case int32:
fmt.Println("int32")
case rune:
fmt.Println("rune")
}
我收到编译错误
tmp/sandbox193184648/main.go:14: duplicate case rune in type switch
previous case at tmp/sandbox193184648/main.go:12
如果我将符文包装在我自己的类型中,则类型开关会编译并工作
type myrune rune
var v interface{}
v = myrune(1)
switch v.(type) {
case int32:
fmt.Println("int32")
case myrune:
fmt.Println("rune")
}
见https://play.golang.org/p/2lMRlpCLzX
这是为什么?如何区分类型开关中的 rune 和 int32?