What type erasure techniques are there, and how do they work?

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

Why following types are reifiable& non-reifiable in java?

Sun/Oracle says the reason is combo of: Need: compile time type checking is sufficient Code size: avoid STL-like code bloat Performance: avoid type checking at runtime that was already done at compile Type erasure ensures that no new classes are created for parameterized types; consequently, generics incur no runtime overhead. In short, 1-5 are reifiable … Read more

Class is a raw type. References to generic type Class should be parameterized

The interface declares the method with a raw type. In that case, you can’t override it nicely without having the warning. The origin of your problem is that the Spring interface was declared to be Java 1.4 compliant. Note that Spring 3.0 is supposed to deliver all classes as Java 1.5 compliant, so that would … Read more

Erasure elimination in scala : non-variable type argument is unchecked since it is eliminated by erasure

It doesn’t work because it will pick out List[Double] or any other list in addition to List[String]. There are a variety of ways of fixing the problem, including wrapping any parameterized types in a non-parameterized case class: case class StringList(value: List[String]) and then you can just mySequence.collect{ case StringList(xs) => xs } to pull out … Read more

Why does unique_ptr have the deleter as a type parameter while shared_ptr doesn’t?

Part of the reason is that shared_ptr needs an explicit control block anyway for the ref count and sticking a deleter in isn’t that big a deal on top. unique_ptr however doesn’t require any additional overhead, and adding it would be unpopular- it’s supposed to be a zero-overhead class. unique_ptr is supposed to be static. … Read more

Scala double definition (2 methods have the same type erasure)

I like Michael Krämer’s idea to use implicits, but I think it can be applied more directly: case class IntList(list: List[Int]) case class StringList(list: List[String]) implicit def il(list: List[Int]) = IntList(list) implicit def sl(list: List[String]) = StringList(list) def foo(i: IntList) { println(“Int: ” + i.list)} def foo(s: StringList) { println(“String: ” + s.list)} I think … Read more