In my Java book, I just read that the following line is not legal:
if (x instanceof Object )
The reason given is that "the array (x) may be of a primitive type, in which case the test will fail". And that's the extent of the explanation - which left me confused.
So I wrote a little test for myself, where x is an int array. When i tried to compile code with that illegal line in it I got a compiler error "Inconvertible types".
Does the compiler test that 1) both arguments are arrays (test passes) 2) element types of both arrays are the same - but it uses arithmetic promotion to promote the int type up to an Object type before doing so (which results in the "Inconvertible types" error)?
Am I on the right track or waaaay off..?
Any help would be really appreciated Thanks! Juliet
posted 11 years ago
The idea is that if the compiler can prove that no object that could be referred to by the left operand could ever be referred to by the right operand, it's a compile time error.
See this thread: saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic&f=24&t=025023