Spot the bug in the generic list helper

from Type erasure
Java 25 LTS intermediate 4 min 1 issue to find

Find why this helper does not establish that every returned element is a `T`.

Java
import java.util.List;

public class Main {
    @SuppressWarnings("unchecked")
    static <T> List<T> castList(Object value) {
        if (!(value instanceof List<?>)) {
            throw new IllegalArgumentException("not a list");
        }
        return (List<T>) value;
    }
}
Open in playground
Report an error