Thanks a lot for your reply, Roel - and especially for the warm welcome!
You're actually one of my heroes because you scored 95%, haha.
Three and a half weeks from now I can post my results too...
Okay, I went through all the Threads you pointed out. That was indeed helpful because I just learned something new about the instanceof operator, namely that I can do this:
(creating the Pizza instance right then and there)
And in the JLS paragraph you quoted in one of the threads it says
The RelationalExpression operand of the instanceof operator must be a reference type or the null type.
So that means "new Pizza()" counts as a
reference type. I didn't know that. Maybe the compiler sees something like this:
That would make sense because the Pizza object itself is on the heap and we're inside a method, so of course the "new Pizza()"-expression must be some kind of reference. And the compiler only cares about the type of this reference.
Likewise, in the example above where we're doing an obvious invalid downcast:
the compiler only sees a
Tree type reference that we're downcasting & passing to the method. Cooooooool... now it makes sense!