#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2005
    Posts
    418
    Rep Power
    20

    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:
    if( !isLeafNode( node ) ){
        InternalNode n = (InternalNode) node;
         ......
    }

    The compiler gives a warning for the line "InternalNode n = (InternalNode) node;". The warning is:
    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
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2010
    Posts
    42
    Rep Power
    4
    Im not a good candidate to answer this question but have you tried putting the code in a try/catch block?
  4. #3
  5. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,711
    Rep Power
    347
    How is node defined? What relationship does it have to InternalNode?

IMN logo majestic logo threadwatch logo seochat tools logo