Printing typed nil

I ran into this https://play.golang.org/p/aJEJiZJDhYa today while debugging. Is this supposed to happen? I would have assumed that it printed something like nil or even nil{}.

The value is nil. But Println represent it as an empty map then printed. https://play.golang.org/p/Ey__aH1ZXtA shows it as nil if you uses Printed and the formatting code %#v

Map and channels are actually pointers to runtime types. When you initialize a map or a channel it creates a pointer that reference to runtime type which is nil. When you print it, it prints the pointer which is not nil, but when you compare it, it compares their referenced values, which is nil.

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