File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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 REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Typecaste confusion" Watch "Typecaste confusion" New topic

Typecaste confusion

Saurabh Pillai
Ranch Hand

Joined: Sep 12, 2008
Posts: 524

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

Joined: Sep 20, 2010
Posts: 4200

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.

The mind is a strange and wonderful thing. I'm not sure that it will ever be able to figure itself out, everything else, maybe. From the atom to the universe, everything, except itself.
Saurabh Pillai
Ranch Hand

Joined: Sep 12, 2008
Posts: 524
Thank you Stephan.
I agree. Here's the link:
subject: Typecaste confusion
jQuery in Action, 3rd edition