This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes Java in General and the fly likes Generifying a class - unchecked cast Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Generifying a class - unchecked cast" Watch "Generifying a class - unchecked cast" New topic
Author

Generifying a class - unchecked cast

D. Ogranos
Ranch Hand

Joined: Feb 02, 2009
Posts: 214
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

Joined: Oct 27, 2005
Posts: 19541
    
  16

That's actually kind of cheating since Class.cast uses the same unchecked cast, but at least it won't trouble you


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
D. Ogranos
Ranch Hand

Joined: Feb 02, 2009
Posts: 214
Very nice, thank you!
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19541
    
  16

You're welcome.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Generifying a class - unchecked cast
 
Similar Threads
Generics question
Generics
inheritance question
Polymorphics and Generics.... how to do specific things to a subclass
Unchecked cast/conversion warnings