Linked by Rüdiger Klaehn on Thu 5th Aug 2004 05:00 UTC
.NET (dotGNU too) One of the most awaited features of Microsoft .NET 2.0 is generics. Generics promise to increase type safety, improve performance, reduce code duplication and eliminate unnessecary casts. The most obvious application of generics in the framework class library are the generic collections in the new System.Collections.Generic namespace. Much has been written about those, but they are not the topic of this article.
Permalink for comment
To read all comments associated with this story, please click here.
re: The problem with IArithmetic
by andy on Thu 5th Aug 2004 08:39 UTC

Making primitives implement IArithmatic would mean you throw away primitives and make them all objects.

They'd only be boxed when you refer to them through an IArithmetic variable. In the same way that they aren't boxed just because they implement IComparable.

Besides, as far as I understand it the Microsoft runtime creates specialised instances of generic classes when the type parameter is a primitive type. In the example in the article, Point<int>, Point<float> and Point<double> would each be specialised for their respective parameter types, so that no IComparable boxing would be necessary.

That's obviously a size-speed tradeoff.