EGOPOLY

Topics include: programming, Apple, Unix, gadgets, large-scale web sites and other nerdy stuff.

Inscrutable Java Warning

2006-08-30 20:35:13

In my eclipse environment, I get warning like this. I never remember the point of them, and whether I should worry:

Type safety: The cast from Object to ArrayList<String> is actually checking 
against the erased type ArrayList.

I found this nice, concise description here:

The compiler is warning you that the cast you are doing is only ensuring the Object is an ArrayList. It can't tell if it truly is an ArrayList<String>. If it isn't, on your head be it. If it is not really an ArrayList< String> expect a ClassCastException as soon as you do a get, even though there are no explicit casts near the get in your code. The problem in essense is that serialised objects contain no record of their generic type. Many think that design decision was a big mistake.

Ugh.