public class Test {
public static void main(String[] args){ //for argument '0'
Object o;
Boolean b = true;
o = b;
if(o); // wont compile
if((Boolean)o);
if(b);
}
}
Remember that compiler cannot run the code. It cannot know what o will point to at run time. It only has the type declaration of o to go by and since the declared type of o is Object, o can point to any object (not just Boolean) at run time (every object is an Object) and so, the compiler cannot compile if(o).
It is a bit strange to me that you can just past a reference variable into IF. I would thought that only boolean primitives can be passed in or expressions that evaluate to boolean?