3 ms·
interface{} is the new void*. There are far better ways to handle generics in modern languages, which preserve type safety and aren't very cumbersome.
by twblalock 10y ago
interface{} is the new void*.
There are far better ways to handle generics in modern languages, which preserve type safety and aren't very cumbersome.
- masklinn 10y ago> interface{} is the new void*. More like Java's Object, especially since downcasts are mandatorily runtime-checked. And the results are exactly what one could have expected from the first 10 years of java (if slightly subdued as Java only had a single magical blessed buildin type) given the language is in more or less the same class.
- mseepgood 10y agoMore like C#'s "object" than Java's "Object".
- 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*/ }