IdentityHashMap.EntrySet.toArray(Object[]) doesn't return a value which follows the type of the array which is passed in.
import java.util.*;
public class ihashmap {
public static void main(String[] args) {
IdentityHashMap hm = new IdentityHashMap();
Set set = hm.entrySet();
String[] array = (String[]) set.toArray(new String[0]);
}
}
Compile this with 1.4.2. Running with 1.4.2 succeeds but 1.5.0 fails with
Exception in thread "main" java.lang.ClassCastException: [Ljava.lang.Object;
at ihashmap.main(ihashmap.java:7)
The code explains it all.
public <T> T[] toArray(T[] a) {
return (T[])toArray(); // !!!!
}