4 ms·
OTOH the feature demonstrated here is discriminated unions, He is storing interface{}, which is a fat pointer (a tuple of the pointer and type pointer). I don
by danieldk 12y ago
OTOH the feature demonstrated here is discriminated unions,
He is storing interface{}, which is a fat pointer (a tuple of the pointer and type pointer).
I don't see what is revolutionary and how most statically typed languages don't handle that case. Sure, in Java the type pointer is stored in the actual instance and not in a fat pointer, but it doesn't make a difference in data structure design.
You can do the same abstraction in Java, C++, and C#. Which covers probably 90% of the statically-typed languages out there.
Edit: note on the last Java example: an if statement with instanceof look prettier ;).
- masklinn 12y ago> Edit: note on the last Java example: an if statement with instanceof look prettier ;). Sure, and an if or switch on .(type) in go probably looks better as well.
- hornetblack 12y ago> switch on .(type) For anyone wondering switch val := heap.Pop(key).(type) { case (*MyType): // We're all good default: // Didn't get a (*MyType) }