In the following scenario I have a method which accepts 2 arrays of Type E. It was my understanding that this E parameter means that both the arrays can be any type, but they must be the same (as I derived from this question). I've tested this with two arrays, one Integer and one Double, but I'm not receiving any error. The output I receive is '14' which is the combined size of both arrays without any error thrown.
Could someone shed some light as to why this works?
public static <E> void showCombinedLength(E[] array1, E[] array2){
System.out.println(array1.length + array2.length);
}
public static void main(String[] args) {
Integer[] integerArray = {1, 2, 3, 4, 5, 6, 7};
Double[] doubleArray = {1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7 };
PrintArray.showCombinedLength(integerArray, doubleArray);
}
Output:
14