Why can't I assign type's value to an interface implementing methods with receiver type pointer to that type?

前端 未结 4 1893
借酒劲吻你
借酒劲吻你 2021-02-08 19:53

I am 2-days old in the world of Golang, and going through the go tour. I couldn\'t help but notice a peculiarity which I cannot seem to be able to come at terms with a

4条回答
  •  不要未来只要你来
    2021-02-08 20:26

    Values stored in an interface are not addressable - but why? See here for the answer.

    tl;dr its because a pointer to A which points to a value of type A in an interface would be invalidated when a value of different type B is subsequently stored in the interface.

提交回复
热议问题