Archive for January 20th, 2009

Fun With Generics

Tuesday, January 20th, 2009

I was trying to declare a array variable this morning:

Map<String, String>[] mapArray = new Map<String, String>[2];

However, the compiler reports an error with the above statement: “Cannot create a generic array of Map<String,String>”. I had to replace the statement with:

Map<String, String>[] mapArray = (Map<String, String>[]) new Map[2];

!?! If one of the goals of generics was to eliminate casts, it certainly failed here.