Cannot type switch on non-interface value

前端 未结 4 2034
礼貌的吻别
礼貌的吻别 2021-02-04 00:51

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条回答
  •  忘掉有多难
    2021-02-04 01:12

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

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

提交回复
热议问题