3 ms·
>interface{} is the new void* There is an important difference between interface{} and void* which makes it a lot less reckless. AFAIK interface{} contains not
by leaveyou 10y ago
>interface{} is the new void*
There is an important difference between interface{} and void* which makes it a lot less reckless. AFAIK interface{} contains not only a pointer to data but also a reference to the type of the data. Therefore you can cast that data safely to the original type (or use "switch" on the type).
if origData, ok := data.(OriginalType); ok { /safe to use origData here*/ }