package kamkor.covariance;

import org.junit.Test;

public class CovariantArrayExample {

	// Scala solves this by making its Arrays invariant (nonvariant)
	@Test(expected = ArrayStoreException.class)
	public void covariantArraysLeadToRuntimeExceptions() {
		String[] c1 = { "abc" };
		Object[] c2 = c1;
		// OOPS! Line below throws a runtime exception: ArrayStoreException
		// Reason is, that c2 is actually an instance of String array, and
		// we try to update it with an Integer.
		c2[0] = 1;
	}

}

@@ -261,18 +261,23 @@
 tring%5B%5D 
-c1
+strings
  = %7B %22ab
@@ -297,15 +297,25 @@
 t%5B%5D 
-c2 = c1
+objects = strings
 ;%0A%09%09
@@ -403,18 +403,23 @@
 s, that 
-c2
+objects
  is actu
@@ -504,10 +504,15 @@
 .%0A%09%09
-c2
+objects
 %5B0%5D 

Refactor Java covariant array example