Unexpected behavior - Looking for explanation


Came across something that I find to be very weird:
I have created a minimal example : goplayground

Why is the interface seen as not nil in test1?
I taught that “interface{}” can be interpreted as “map[string]interface{}” ?

Whats the logic behind this?

It’s not nil in test1 because a is of not type interface{}, so one is created to “wrap” a.

A variable of an interface type can hold a value of a type that implements the interface .

I tweaked your playground here to unwrap itf in test1 Go Playground - The Go Programming Language

Interface can hold a nil value, being itself not nil: A Tour of Go
Go Playground - The Go Programming Language

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.