Cannot type switch on non-interface value

前端 未结 4 1941
礼貌的吻别
礼貌的吻别 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:25

    There are two kinds of type conversions

    1. conversion between basic data types. For this we can use the direct casting

      i := 48

      str := string(i)

    2. But type conversion using value.(type) is for conversion among the class hierarchy, (e.g. where we want to get the specific implementation from the interface). Else, we get the above error.

提交回复
热议问题