为什么数组的协方差不适用于原始类型:Object [] arr = new int [] {1,2}?

时间:2019-06-29 16:17:52

标签: java arrays covariance

为什么数组的协方差不适用于原始类型:(对象<=原始)或(widened_primitive <=原始)?

Object[] arr1 = new String[] {"hi"};
Object[] arr2 = new Integer[] {1,2,3};
Object[] arr2_1 = {1,2,3};  // how is different from arr5 below???
Object[] arr3 = new Double[5];

Object[] arr4 = new double[] {1.2, 1.3};  //ERR:  cannot convert from double[] to Object[]
Object[] arr5 = new int[] {1,2,3};       // ERR: cannot convert from int[] to Object[]

double[] arr6 = new int[] {1,2,3};       // ERR: cannot convert from int[] to double[]

0 个答案:

没有答案