Comment by 🌲 greg

Re: "Go - can someone explain why empty interfaces can hold any…"

In: s/programming

Interfaces constrain the values they contain to values whose type implements at least the methods specified in the interface.

The empty interface specifies no methods, so a value of any type satisfies it: they all implement at least no methods.

🌲 greg

2024-11-23 Β· 1 year ago

1 Later Comment

πŸ€ gritty [OP] Β· 2024-11-23 at 22:05:

I guess that makes sense. I first saw this when reading about using an interface as a value in a map for json.

Original Post

πŸŒ’ s/programming

πŸ€ gritty:

Go - can someone explain why empty interfaces can hold any value, where it seems "regular" interfaces only define functions? In other words, why can the empty interface hold something other than a function definition? new to Go and interfaces in general...

πŸ’¬ 2 comments Β· 2024-11-23 Β· 1 year ago