Interesting example.
The ClassCastException is probably thrown during conflict resolution
in hash data structure. I don't know how are the conflicts resolved,
didn't bother to go through the source code but let's assume this
is a List.
Let this list contain two indexed
String objects:
[ 6 ; String:"New York" ]
[ Dog ; String:"Canada" ]
Now, if you run get(6) you'll need to iterate this conflict list to
find your key, and since there are *heterogeneous* keys in this list
there is no way you'll get your object unless it's first in this list
or all objects preceding the one you're looking for are of the same type,
namely int - otherwise you'll get ClassCastException on first non-int key.
Try reordering lines of your code to see that in some insertion configurations the code *will* work.
[ December 11, 2007: Message edited by: Lucas Lech ]
[ December 11, 2007: Message edited by: Lucas Lech ]