Java ate my brain
Aug. 17th, 2007 08:00 amJava's generics are hard. And I think they're defined wrong.
This is clearly a bug in the design of the language.
Also, ObjectInputStream.readObject(), which returns Object, appears to have no way of assigning to a templated type without warning without adding the annotation @SuppressWarnings({"unchecked"}) to the function. Hmpf. Shoulda stuck with Java 1.4
HashMap<String,String>[] arrayOfHashMap; // Ok, I can declare this arrayOfHashMap[0] = new HashMap<String,String>(); // this compiles just fine HashMap<String,String> instanceOfHashMap = arrayOfHashMap[0]; // this works fine in code too arrayOfHashMap = new HashMap<String,String>[]; // but this always is a compiler error! arrayOfHashMap = new HashMap[]; // and this is a warning! I can't win!
This is clearly a bug in the design of the language.
Also, ObjectInputStream.readObject(), which returns Object, appears to have no way of assigning to a templated type without warning without adding the annotation @SuppressWarnings({"unchecked"}) to the function. Hmpf. Shoulda stuck with Java 1.4