Mat*_*art 3 java arrays floating-point
我已经写了一段时间的Java,甚至开始把它教给别人.我发现很难向新学生解释为什么必须对浮点数组的值进行转换.例如:
float[] someArray = {(float) 23.23, (float) 123.1, (float) 123.1};
int[] intArray = {12, 13, 4, 5};
double[] doubleArray = {22.12, 23.1, 12.1};
Run Code Online (Sandbox Code Playgroud)
我猜测包含小数的值只是被视为双打而不是浮点数,因此需要进行投射.Java选择它的原因是什么,编译器也不能认为因为它是一个浮点数组,它会采用浮点值吗?