Can I type assert a slice of interface values?

前端 未结 2 884
情歌与酒
情歌与酒 2020-12-09 16:36

I am trying to type assert from a []Node, to []Symbol. In my code, Symbol implements the Node interface.

Here is

2条回答
  •  悲&欢浪女
    2020-12-09 17:25

    Go does not allow this. You need to convert Node to Symbol individually.

    The reason why it isn't allowed is that []Node and []Symbol have different representations, so the conversion would need to allocate memory for []Symbol.

提交回复
热议问题