While writing code to check the datatype of entries in a Java 11 array, I came across a compile-time error which I can't seem to find anywhere on Google or SO. I'm using JetBrains's IntelliJ IDEA, and the editor is giving me the error "Inconvertible types; cannot cast 'double' to 'double'." for the second line in the following MWE (that is, put inside a main
method etc.):
double[] arr = new double[] {0.1, 0.2};
boolean result = arr[0] instanceof double;
I don't really get what's wrong here. Isn't instanceof
exactly analogous to Python's isinstance
? New to Java (not to Python nor the Java derivative Processing), so this baffles me.