Skip to content

ceggert/JavaArrayCovariance

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 

Repository files navigation

JavaArrayCovariance

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.

About

A short example of Java's array covariance, which is a flaw in the Java language design.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published