[Mono-list] How do I reference generic classes in C#???

Jonathan Pryor jonpryor at vt.edu
Sat Jan 10 13:46:15 EST 2009


On Sat, 2009-01-10 at 02:38 -0800, Luke B wrote:
> Good read. You got me wondering why type erasure is used. From the
> Java site:
> 
> Type erasure enables Java applications that use generics to maintain
> binary compatibility with Java libraries and applications that were
> created before generics. 

The problem is, they failed.  The _original_ intent, as I remember it
when doing Java development, was that Java 1.5 libraries could still be
used by the Java 1.4 development chain, i.e. you could use generic
classes from a non-generic runtime, etc.  Had this *actually* been the
case, the tradeoffs would likely have been acceptable.

Alas, that is not the case; they had to change class file format anyway,
thus preventing 1.5 .class files from being loaded into a 1.4 runtime.  

Furthermore, back in 1999 there were Java generic efforts that mirrored
what .NET has -- actual distinct generic types, the use of value types
within the generic system (so you could have an ArrayList<int>
implemented atop an int[] as opposed to the Java 1.5 List<Integer>
implemented atop an Object[]).  It was rejected because...it introduced
incompatible changes to the runtime (shock!  horror!).

> That might be why it feels more "natural" to me than the .NET stuff,
> just because I have a long history with Java. You're probably right on
> the .NET system being better in the long run, it was designed at a
> time when they could take all the lessons and mistakes of Java into
> account...

That can't be entirely true, either.  Java 1.5 was released in September
2004, while .NET 2.0 was released in November 2005.  14 months is not
enough time to get feedback from the Java release and introduce any
major changes.

For that matter, I know that MSR was looking into generics *before* .NET
1.0 was released (and found a few semantics issues in the BCL because of
it that were subsequently fixed), so it really doesn't make sense to
state that .NET was building off of Java's failures.  The issues with
erasure were known well before Java 1.5 was released; Sun was just
willing to live with those restrictions.

 - Jon




More information about the Mono-list mailing list