• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

generic method

 
Ranch Hand
Posts: 375
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
when I do

public void testMethod(List<? extends Account> accts) {

}

the argument is "<? extends Account>" . I know it takes List of the objects of sub classes of "Account". Does it take a List of "Account" objects ? I passed a list of objects of "Account' type and it doesn't complain in compiler but it gave me problem at run time. Basic question is --- Can I pass a list of objects of "Account" ??
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ben,
What error do you get? Is it on inserting Account objects to the list?
 
ben oliver
Ranch Hand
Posts: 375
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The error is from somewhere else so I am not sure. But I know it happened after I started using the above generic stuff. It will be helpful if you can help me clarify the concept first --- Can I pass a list of objects of "Account" type ? or can I just pass a list of its sub-class ?
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"? extends Account" means you can use anything that IS-A Account - so that includes Account itself.
reply
    Bookmark Topic Watch Topic
  • New Topic