Cannot type switch on non-interface value

前端 未结 4 2069
说谎
说谎 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条回答
  •  南笙
    南笙 (楼主)
    2021-02-04 01:17

    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.

提交回复
热议问题