Type erasure techniques

All type erasure techniques in C++ are done with function pointers (for behaviour) and void* (for data). The “different” methods simply differ in the way they add semantic sugar. Virtual functions, e.g., are just semantic sugar for struct Class { struct vtable { void (*dtor)(Class*); void (*func)(Class*,double); } * vtbl }; iow: function pointers. That … Read more

How do I get around type erasure on Scala? Or, why can’t I get the type parameter of my collections?

This answer uses the Manifest-API, which is deprecated as of Scala 2.10. Please see answers below for more current solutions. Scala was defined with Type Erasure because the Java Virtual Machine (JVM), unlike Java, did not get generics. This means that, at run time, only the class exists, not its type parameters. In the example, … Read more