A question specific to generics in Java, and their usage with instanceof:
For the following if-statement: if (((NodeInternal<Value>) parent).NW() instanceof NodeLeaf<?>)
I need this cast in order to access the parent‘s NW. NW is a property of parent which is of type NodeInternal.
I need to check if the reference pointer held by NW is an instance of NodeLeaf<?>. A runtime error is produced: NodeLeaf cannot be cast to NodeInternal. This is because leaf is cast as an internal, however, the cast should be only for parent to be able to access NW().
How would I fix such a problem?
Thank you
Well, I guess I commented first so I’ll do the honors 🙂
The explanation is that
parentis in fact of classNodeLeafand notNodeInternal.