• Post Reply Bookmark Topic Watch Topic
  • New Topic

generic method  RSS feed

 
ben oliver
Ranch Hand
Posts: 375
  • Mark post as helpful
  • send pies
  • 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" ??
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 37507
551
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • 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
  • 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 ?
 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"? extends Account" means you can use anything that IS-A Account - so that includes Account itself.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!