
October 9th, 2012, 04:33 AM
|
|
|
|
Am I casting incorrectly or is this unavoidable?
Hi,
I have a tree where each node is of type Node. Some nodes are LeafNodes which is a subclass of Node. Other nodes are InternalNodes which is also a subclass of Node.
java Code:
Original
- java Code |
|
|
|
if( !isLeafNode( node ) ){ InternalNode n = (InternalNode) node; ...... }
The compiler gives a warning for the line "InternalNode n = (InternalNode) node;". The warning is:
Quote: | Type safety: Unchecked cast from Node to InternalNode |
Is there something I should/can do to prevent this warning from occurring? Or is this unavoidable and I can just suppress the warning?
Thanks in advance,
Stefan1
|