Created
June 16, 2016 09:52
-
-
Save toandv/6554f7ed9c3294a41d48e4b10a8b8d8e to your computer and use it in GitHub Desktop.
Array Covariance
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Arrays are covariant in Java, but it's not necessary. | |
String[] s = new String[2]; | |
Object[] o = s; | |
o[0] = 1; // ArrayStoreException | |
// Arrays in Scala are not covariant | |
val a: Array[NonEmpty] = Array(new NonEmpty(1, Empty, Empty)) | |
val b: Array[IntSet] = a // Compilation error |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment