A short example of Java's array covariance, which is a flaw in the Java language design.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.



A short example of Java's array covariance. This is considered a flaw in the design of the Java language. Ideally, Java should exhibit subtype invariance, in which an array of type "X array" is a subtype of "Y array" only if X <: Y and Y <: X. However, Java only checks the former (X <: Y, called covariance), which means the compiler will not check certain array assignments for type safety. This check is therefore done at runtime and can result in the ArrayStoreException being thrown.

This short program demonstrates this flaw.