Possible Duplicate:
C# vs Java generics
Java
use Type erasure while C#
keep type information at runtime, what are the practical difference in the behaviors of the language from this design?
The way to implement generics, the Java compiler applies type erasure to: Replace all type parameters in generic types with their bounds or Object if the type parameters are unbounded. The produced bytecode, therefore, contains only ordinary classes, interfaces, and methods.
C# does not have type erasure. C# has actual generic types deeply baked into the runtime.
Type Erasure is achieved in C++ by encapsulating a concrete implementation in a generic wrapper and providing virtual accessor methods to the concrete implementation via a generic interface.
There are a lot of issues with type erasure. It brings back bad memories. I haven't used Java since 1.6, so this may be out of date, but some things I remember:
class c implements IComparable<MyClass>, IComparable<MyOtherClass>
is impossible.
List<T1>
, List<T2>
, and so on. For example, Java -- How to deal with type erasure in constructors?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With