Pages

Wednesday, July 26, 2006

Word on Generics

Had another java programmer here at work point me at a page complaining about generics
Ken Arnold’s Blog

And because I was interested in the possible performance issues that might be associated with generics, I wanted a read.

But it turned out to be a discuss about the difficulties of using generics. I read the article and I didn’t understand what his problem was. It seemed like he was using generics wrongly.

I though generics where meant to be an aid to prevent typecasting from items. A way to gaurantee that when you put something in of a certain type, it will come out as that type without typecasting.

There was one line in there “Right now, there are some idioms that you cannot code without a type-safety warning, such as creating arrays of generic types”
Unless I’ve missed something, isn’t

List<Thing>[] myList = new ArrayList<Thing>[5] ;// *

All you need to do?

*Code may not compile. I don’t think I’ve set Eclipse for 1.5

-= Comments
1. Matthew Delves | July 25th, 2006 at 12:28 pm
Whilst I am not a big fan of idiot proof code, it does make for more stable programs if and when it is used properly. Surprisingly someone who would be assumed to know Java would not be able to grasp the concept of Generics and convey it to others.

No comments:

Post a Comment