Query on Interfaces

47 views
Skip to first unread message

Prabhu Chawandi

unread,
Jan 7, 2020, 12:18:16 AM1/7/20
to golang-nuts
Hello,

  I was reading this article @ https://blog.golang.org/laws-of-reflection

Excerpt: 

One important detail is that the pair inside an interface always has the form (value, concrete type) and cannot have the form (value, interface type). Interfaces do not hold interface values. 
 
I could not understand it clearly, Can through some clarity with an example?

I tried this and did not give any error.



--
Cheers
p.

Ian Lance Taylor

unread,
Jan 7, 2020, 12:40:59 AM1/7/20
to Prabhu Chawandi, golang-nuts
What this means is that when you write "a = b" where a and b are both
of interface type, then the value that is in b will be copied to a. a
will wind up with the dynamic type and dynamic value that were
originally in b. The dynamic type of a will not become the type of b;
it will become the dynamic type of the value stored in b.

Ian

Prabhu Chawandi

unread,
Jan 7, 2020, 12:48:30 AM1/7/20
to Ian Lance Taylor, golang-nuts
Thank you, it is clear now. 
--
Cheers
p.
Reply all
Reply to author
Forward
0 new messages