I'm using an API that returns two-dimensional float array as a result. I'd like to process this data using the flatMap method from the streaming API, but I need to pass arrays of doubles into its methods. I've tried to work it around by casting float[][] into double[][], but it didn't work, even with float[]. Here's a JShell session dump:
-> new float[] {1.02f, 4.32f, 65.4f}
Expression value is: [F@2b98378d
assigned to temporary variable $1 of type float[]
-> double[] arrayOfDoubles = (double[]) $1
Error:
incompatible types: float[] cannot be converted to double[]
double[] arrayOfDoubles = (double[]) $1;
So, my question is: why can't we cast float[] into double[], when it's fairly legal to cast from float to double?