# warning: [unchecked] unchecked cast to java.util.List<java.lang.String>

- **ID:** `java/compiler-warning-unchecked-cast`
- **Domain:** java
- **Category:** compilation_error
- **Verification:** ai_generated
- **Fix Rate:** 85%

## Root Cause

The compiler emits an unchecked cast warning when a generic type cast cannot be verified at runtime due to type erasure, indicating potential ClassCastException risk.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| Java 8 | active | — | — |
| Java 11 | active | — | — |
| Java 17 | active | — | — |
| Java 21 | active | — | — |

## Workarounds

1. **Use a type-safe pattern with a helper method and @SuppressWarnings("unchecked") only on the minimal scope, with a comment explaining why it's safe: @SuppressWarnings("unchecked") List<String> list = (List<String>) someObject;** (80% success)
   ```
   Use a type-safe pattern with a helper method and @SuppressWarnings("unchecked") only on the minimal scope, with a comment explaining why it's safe: @SuppressWarnings("unchecked") List<String> list = (List<String>) someObject;
   ```
2. **Refactor the code to avoid unchecked casts by using generic methods or type tokens: public <T> T cast(Object obj, Class<T> clazz) { return clazz.cast(obj); }** (90% success)
   ```
   Refactor the code to avoid unchecked casts by using generic methods or type tokens: public <T> T cast(Object obj, Class<T> clazz) { return clazz.cast(obj); }
   ```

## Dead Ends

- **** — Suppression only hides the symptom; the cast remains unchecked and dangerous. (30% fail)
- **** — Raw types bypass generic checks entirely, leading to potential heap pollution and runtime errors. (50% fail)
