Re: light weight types
Peter Duniho wrote:
Mike Schilling wrote:
Peter Duniho wrote:
Though, .NET illustrates that an alternative approach would have
been to simply create a new, parallel group of classes supporting
generics, rather than to insist that the old classes be reusable
via
generics.
It's technically feasible, sure, but given the amount of existing
Java code when 1.5 was introduced, imagine the dumbfoundment with
which a new and incompatible set of, e.g. collections classes (and,
far worse, collection interfaces) would have been greeted.
As Patricia and Arne, I don't see the problem. If anything, by
overloading existing classes, they created problems for legacy code
unnecessarily.
For new code, I don't see how it would matter that the new generic
classes were an entirely new class, rather than taking advantage of
an
existing class. To the coder, it's all-new one way or the other.
What follows is largely hypothtiecal, as the only code I've written
that uses generics is really toy code intended mostly to help me use
to learn generics:
The large body of code I maintain at work has to run in 1.4
environments, so generics are not an option there. When it becomes
possible to start using 1.5 features, I'm going to do so, both in new
classes and when maintaining old classes. And the fact that I can say
List<MyClass> newList = (List<MyClass>)exisitngList; // Safe,
since I know what this list really contains
for (MyClass mc : newList)
{
...
}
will come in very handy. Modifying all the framework methods that
return currently List to return NewFangledGenericList would not have
been feasible. That is, the actual situation allows me to introduce
generics incrementally; this seems to me to be very worthwhile.