高朗类型的断言在同一类型上(还是?)

问题描述 投票:0回答:1

,所以我在这里介意自己的生意,编码...然后进行静态检查,打我的黄色线(我们都知道和讨厌)说 -

type assertion to the same type: (*valPtr) already has type interface{} (S1040)

for _, row := range table {
    for _, colVal := range row {
        valPtr := colVal.(*interface{})
        val := (*valPtr).(interface{})
        switch v := val.(type) {
        case string:
            fmt.Printf("%s\t", v)
        case int64, int32, int, float32, float64:
            fmt.Printf("%d\t", v)
        default:
            fmt.Printf("unknown type\t")
        }
    }
    fmt.Println()
}
我的理解和逻辑

当我在调试中运行该程序时,我可以看到:

因此,我最初从接口到指针转到接口(因为那是存储在(对?)内的类型)。接下来,我将指针指向接口并将其施放到接口 - 这样我就可以做

switch val.(type)

当我要发布这个问题时,正好击中了我...
go
1个回答
0
投票

type assertion to the same type: (*valPtr) already has type interface{} (S1040)

换句话说: typered的

(类型为

valPtr
你为什么要把它扔到*interface{}
again
)??

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.