Andr7st

Andr7st

Covariance, generics and ArrayStoreException

Covariance, generics and ArrayStoreException

Arrays are covariant and generics aren't: why Object[] objects = new String[3] compiles and fails at runtime, why you can't write new T[], and how to live with toArray(T[]).


Written by
Andrés Segura
Id

jaa08

Posted

Sep 25, 2026

Reading time

7 min

java
arrays
generics
covariance
type-safety
On this page
Loading...