Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Typecaste confusion

 
Saurabh Pillai
Ranch Hand
Posts: 524
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 6322
78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 524
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Stephan.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic