Consider the following test of Java\'s ArrayList#toArray
method. Note that I borrowed the code from this helpful answer.
public class GenericTest {
The ArrayStoreException
is runtime exception not compile time and thrown at run time and it indicates that different type of object is being stored in the array.
Object x[] = new String[3];
x[0] = new Integer(0);
The only way you can find it at compile time is by using <Integer> type as below
foo.toArray(new String[10]);
The above will throw compile time error as
The parameterized method
.