Type safety: Unchecked cast

The problem is that a cast is a runtime check – but due to type erasure, at runtime there’s actually no difference between a HashMap<String,String> and HashMap<Foo,Bar> for any other Foo and Bar.

Use @SuppressWarnings("unchecked") and hold your nose. Oh, and campaign for reified generics in Java 🙂

Leave a Comment