Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Collections mock question

 
adam Lui
Ranch Hand
Posts: 186
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


why would line 10 generate compatible error?!
 
sathi jogi
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

here you are trying to retrieve the list objects from the arraylist, that is not right, you are retrieving objects from the list,

so modify the line 10 as given below,

for (Object obj:getList()) //line 10
System.out.println(obj);
}
 
adam Lui
Ranch Hand
Posts: 186
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
so we use ....
for (Object obj: getlist())

wat about ...
for (ArrayList obj: getList())

possible?
 
al nik
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it's possible if for example your getList() method returns a "List of ArrayList"


but this is not your case..
[ October 21, 2007: Message edited by: al nik ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic