• Post Reply Bookmark Topic Watch Topic
  • New Topic

(generics) Casting List of type A to type B  RSS feed

 
Pho Tek
Ranch Hand
Posts: 782
Chrome Python Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can this be done?



This code does not compile since "stuff" does not match up with the return type. Is there a way to make this work while keeping the method signature unchanged ?

Thanks

Pho
 
Burkhard Hassel
Ranch Hand
Posts: 1274
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Pho,


no, if your method declaration is like this, you must return a List<Foo>.

But there should be no major problem. To a List<Foo> you can add FooNG objects, as a FooNG IS-A Foo:




Yours,
Bu.
 
Pho Tek
Ranch Hand
Posts: 782
Chrome Python Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok. Thanks.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!