Cannot type switch on non-interface value

前端 未结 4 2064
说谎
说谎 2021-02-04 01:01

I am playing with type assertion using the following dummy code, and I got the error:

cannot type switch on non-interface value

Doe

4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-04 01:18

    I figured out the answer, which is to cast n to interface{} before the type assertion:

    switch v := interface{}(n).(type)
    

提交回复
热议问题