Java Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesJava Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 9th, 2012, 04:33 AM
Stefan1 Stefan1 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2005
Posts: 399 Stefan1 User rank is Sergeant (500 - 2000 Reputation Level)Stefan1 User rank is Sergeant (500 - 2000 Reputation Level)Stefan1 User rank is Sergeant (500 - 2000 Reputation Level)Stefan1 User rank is Sergeant (500 - 2000 Reputation Level)Stefan1 User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 5 Days 20 h 48 m 7 sec
Reputation Power: 19
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
  1. if( !isLeafNode( node ) ){
  2.     InternalNode n = (InternalNode) node;
  3.      ......
  4. }

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

Reply With Quote
  #2  
Old October 9th, 2012, 05:21 AM
Corpsecreate Corpsecreate is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2010
Posts: 42 Corpsecreate User rank is Private First Class (20 - 50 Reputation Level)Corpsecreate User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 Day 4 h 25 m 17 sec
Reputation Power: 3
Im not a good candidate to answer this question but have you tried putting the code in a try/catch block?

Reply With Quote
  #3  
Old October 9th, 2012, 09:25 AM
NormR's Avatar
NormR NormR is offline
Contributing User
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Aug 2010
Location: SW Missouri
Posts: 3,048 NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Week 6 Days 16 h 53 m 14 sec
Reputation Power: 346
How is node defined? What relationship does it have to InternalNode?

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesJava Help > Am I casting incorrectly or is this unavoidable?

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap