A Case for Generics
By Dkildahl -Oracle on Jun 01, 2011
Forget about my wish list from last month. There are a few really good ideas on that list (closures and super packages). I gave up on properties. The rest is about making generic types easier to use. However, during my recent hiatus in Europe, I have been reflecting on generics. What is the problem with generics? Is it too complicated?
No doubt, generic types are relatively new in mainstream programming languages and wildcards are truly unique: it was literally invented for the Java™ programming language. This means that a lot of developers are not yet comfortable with generics. When I first heard about Object-Oriented Programming, I found it really scary. All that about inheritance, overriding, overloading, is-a, and has-a. Frankly, there is still a lot of confusion about something as fundamental as is-a, and has-a.
Most developers are very comfortable with OOP. In five years, most developers will be comfortable with generics.
Generic types are taking a lot of heat on various blogs. Not all of the critisism is without substance. I see that there is a problem when I talk to developers and close compiler bug reports as not being a bug. I see that there is a problem when trying to teach generics. I see that is a problem that causes otherwise diligent developers ignore a whole category of warnings about potential type unsafety in their programs.
The problem is the lack of reification. In other words, the lack of runtime type-information about generic types (at runtime, you cannot tell an
ArrayList<String> from a
ArrayList<Integer>). We need to do something about that. It is indeed time to erase erasure!
In the next weeks I'll explain what it buys us and how we can accomplish it.