Compilation error in converting Java objects
I have a problem and I am wondering if anyone knows why:
if(n.getInfo() instanceof Token){
//Token abc = n.getInfo();
System.out.print("ouch!");
}
when it starts, it outputs ouch!
.
However, when I uncomment the line
Token abc = n.getInfo();
it gives compilation error:
error: incompatible types: Object cannot be converted to Token
Token abc = n.getInfo();
I don't understand since it is an instance Token
, so how cannot it be converted to Token
?
Thank.
+3
source to share