.comment-link {margin-left:.6em;}

Pupil

Sunday, November 13, 2005

Generics in the Java Language

Sun introduced Generics with Java 1.5 recently.

Whenever a developer created a Collection in older versions of Java, he had to rely on run-time checking to enforce type safety in the Collection. Run-time checked does provide flexibility. However, 90% of the time, Developer's never really designed to use that flexibility. Imagine creating a Collection of different types of Objects with nothing in common, how often would one have to solve a problem that required just that? Even in that 90%, 10% of the time, that flexibility was abused. Now Imagine writing an interface that takes a Collection as an argument. Let's say there exist two different implementations of that interface (or template) that expected a Collection each with types that differ from the other. The horrors, the interface designer never intended the interface to be used in that way. Thus, interchangeability is not enforceable.

I just did rely on anecdotal evidence to justify the use of Generics. A very obvious example.

Yes, Generics is just as much a fix as it is a feature.

This is my repository of articles and people on Generics.

Generics in the Java programming Language. [Sun.com]
Generics in the Java programming Language. [Sun.com] -- A tutorial by Gilad Bracha.
Bruce Eckel's Java weblog. [Artima] -- if your not happy with just the tutorial but want to look at the advanced material, hop over to Eckel's journal and follow his Generics blogs. Or, :-) just get your own Blog up and running and send me a link.

0 Comments:

Post a Comment

<< Home