How are interfaces represented in Go?

前端 未结 2 1301
孤城傲影
孤城傲影 2021-01-06 18:06

I\'m reading through two articles right now and am a little confused.

This article - http://blog.golang.org/laws-of-reflection says

> var r io.Re         


        
2条回答
  •  無奈伤痛
    2021-01-06 18:27

    Both are correct, r "holds" (tty, *os.File) and that is what the second article says. Note that Laws of Reflection is a bit more high-level and does not mention implementation details (which might change in each release) like discussed in the second article. The diagram of the second article read as follows: "s contains schematically (b, *Binary). s is of type Stringer, its data is a Binary with value 200 and s's itable contains one method String and the other methods of Binary (or *Binary) are not represented in the itable and thus not accessible for s.

    Note that I think the actual implementation of interfaces in Go 1.4 is different from what the second article (Russ's?) states. "

提交回复
热议问题