3 ms·
I think interface{} is a great feature, when you want to write code that safely handles any type. fmt.Printf is a great example for this. As type information is
by _ph_ 7y ago
I think interface{} is a great feature, when you want to write code that safely handles any type. fmt.Printf is a great example for this. As type information is attached with the value, type safety is fully maintained when casting the contained value back to its right type.
Where it is appropriate, it is a very cool thing that you can have fully dynamically typed variables with all safeties in place. Of course, it shouldn't be used in place of better abstractions, like specific interfaces or properly factored code.