I have a problem and I'm wondering if anyone knows why:
if(n.getInfo() instanceof Token){
//Token abc = n.getInfo();
System.out.print("ouch!");
}
when it runs, it prints out ouch!.
However, when I uncomment the line
Token abc = n.getInfo();
it gives a compile error:
error: incompatible types: Object cannot be converted to Token
Token abc = n.getInfo();
I don't understand, as it is an instance of Token, so how it cannot be converted to Token?
Thanks.
instanceofit probably means you're doing something not very OO style. I'd say it's a telltale sign to have a good look at your code.