I (mistakenly) wrote the following code in an Android project.
for (Map<String, Object> occurrence : occurrences) {
if (occurrence.get("cancelled") == true) {
// don't display cancelled events
continue;
}
...
Now, as I understand it, what should have happened there is a compiler error to the effect of error: incomparable types: Object and boolean
, but that's not what happened. It compiled successfully, and behaved the way I had expected/intended. (It is true that the value that will be retrieved here will always be a boxed boolean
.)
I never even would have noticed this, but some time after I submitted the code, a collaborator pulled to his system, tried to compile, and got a compile error.
After that happened I double checked to make sure, but my code is definitely using the ==
operator, and it still compiles fine even after cleaning and rebuilding.
What's going on here? Is there some setting to tell Android Studio to gloss over this? Do different versions of the java toolchain allow or disallow this syntax? I've got this particular example working by just replacing the comparison with a call to .equals
, but we need to be sure in the future that when we write/compile/test code it won't randomly not work at all on the other guy's machine!