This week's book giveaway is in the Beginning Java forum.
We're giving away four copies of Murach's Java Programming and have Joel Murach on-line!
See this thread for details.
Win a copy of Murach's Java Programming this week in the Beginning Java forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Generifying a class - unchecked cast  RSS feed

 
D. Ogranos
Ranch Hand
Posts: 214
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, yet another generics question (didn't find something similar to this in the search). I have some classes which share a common pattern but make use of specific types. It appears they would be a good candidate for generifying. So far I have created a new abstract generic base class which should take most of the functionality of each current class. However I still get an "unchecked cast" warning.



Is there a way to avoid the unchecked cast warning? Or is it safe to ignore it here? Or is there a better way to write this all?
 
Rob Spoor
Sheriff
Posts: 21019
84
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's actually kind of cheating since Class.cast uses the same unchecked cast, but at least it won't trouble you
 
D. Ogranos
Ranch Hand
Posts: 214
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Very nice, thank you!
 
Rob Spoor
Sheriff
Posts: 21019
84
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome.
 
Why fit in when you were born to stand out? - Seuss. Tiny ad:
Thoughts on deprecation in Java
https://coderanch.com/t/683016/java/Deprecation-Java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!