permaculture playing cards*
The moose likes Beginning Java and the fly likes Typecaste confusion Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Typecaste confusion" Watch "Typecaste confusion" New topic
Author

Typecaste confusion

Saurabh Pillai
Ranch Hand

Joined: Sep 12, 2008
Posts: 506

I can call first method like save(myCustomObject); but when I call saveAll(myCustomObjects), (myCustomObjects is List<MyCustomObject>) it gives me compilation error.
.
Why?
Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 3581
    
  14

Because List<SubType> is not a subtype of List<Type>.

Instead, your method declaration should probably look like:
Read more about it in Oracle's Java Tutorials, the Generics trail.
Saurabh Pillai
Ranch Hand

Joined: Sep 12, 2008
Posts: 506
Thank you Stephan.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Typecaste confusion
 
Similar Threads
JAXB Saving and loading a generic List of type T to/from XML
PropertyChangeListener - FocusListener - which one do I use
Exception Interceptor Throws Advice
Generics Doubt
Generics Lower and Upper Bound