jshell || instanceof
Remi Forax
forax at univ-mlv.fr
Fri Jan 17 18:06:36 UTC 2020
There is a bad interaction in between jshell and the way instanceof is specified to work with a ||
void plus(Number v1, Number v2) {
if (v1 instanceof Integer i1 || v2 instanceof Integer i2) {
System.out.println(i1);
System.out.println(i2);
}
}
plus(1, 2);
| created method plus(Number,Number), however, it cannot be invoked until variable i1, and variable i2 are declared
| attempted to call method plus(Number,Number) which cannot be invoked until variable i1, and variable i2 are declared
Neither i1 nor i2 is inserted in the scope, so jshell reports logically that the method will work when i1 and i2 will be defined, so it works as intended but it's confusing.
The root of the issue is that piggybacking on inserting variables or not in the scope let to poor and confusing error message.
Rémi
More information about the amber-dev
mailing list