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

Luke B muchomuse at gmail.com
Sun Jan 11 02:07:15 EST 2009


Huh. Yeah, I don't really know the history of Generics in each language. I'm
assuming there's value in the .NET model, but I still find the Java model
more intuitive to program in. The reason is that I think of Generics as
something that are "contained" in a class, while being separate of the
class. So something like:
Mug<Cocoa> yourdrink = new Mug<Cocoa>();
Mug<Coffee> mydrink = new Mug<Coffee>();
Mug.topology = Doughnut;
makes more sense, I the general shape of all Mugs shouldn't be dependent on
what liquid they contain. I can see the value of the dotnet approach too,
but its just simply less intuitive.


On Sat, Jan 10, 2009 at 10:46 AM, Jonathan Pryor <jonpryor at vt.edu> wrote:

> 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
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-list/attachments/20090110/14e12d17/attachment.html 


More information about the Mono-list mailing list