Raw Types
Fast recall
Quick revision
Core answer
List instead of List. It exists only for backward compatibility with pre-generics code. Avoid it because it disables compile-time type checking, reintroduces unchecked casts, and can cause ClassCastException at runtime.Whether you know raw types defeat generics and only exist for legacy compatibility
Confusing a raw type List with List<Object>, or not knowing it triggers unchecked warnings
Note List<Object> is still type-checked, while raw List opts out of checking entirely
Interview-ready guide
Interview answer
A raw type is a generic type used without its type parameter.
So writing List instead of List of String, or Map instead of Map of String comma Integer — that's a raw type. They only still exist in the language for backward compatibility, so that code written before generics arrived in Java 5 still compiles. The problem is that using a raw type basically turns generics off.
The compiler stops checking what you put into the collection, so you can mix a String and an Integer in the same list with no complaint at compile time. Then when you read elements out and cast them, you can get a ClassCastException at runtime — exactly the kind of bug generics were designed to prevent.
The compiler does warn you with an unchecked warning, which is its way of saying type safety is no longer guaranteed here. One distinction that's worth calling out, because it trips people up, is that List of Object is not a raw type. List of Object is fully type-checked; it just happens to accept any object.
The raw List, on the other hand, opts out of type checking entirely, and that's the dangerous part. So the bottom line is: always supply the type parameter in new code. If you genuinely need a collection of any object, use List of Object so you keep compile-time checking, and never fall back to a raw type just to silence the compiler.
Raw Types
Direct Answer
A raw type is a generic type used without its type parameter — e.g. List instead of List<String>. It exists only for backward compatibility with pre-generics code. Avoid it because it disables compile-time type checking, reintroduces unchecked casts, and can cause ClassCastException at runtime.
Common Mistakes & Pitfalls
- Confusing raw
ListwithList<Object>. The latter is type-checked; the raw one isn't. - Ignoring unchecked warnings. They're the compiler telling you type safety is off.
- Using raw types to 'simplify'. It only defers errors to runtime.
- Mixing raw and generic APIs. Passing a raw type can poison type inference and re-introduce casts.
Check your understanding
Answer these without looking back at the article.
- What warning does Java give for raw types?
- When is using raw types acceptable?
Looking for a structured roadmap?
Every module on this page is also part of the full Java backend interview track.