Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

advanced for loop: foreach not applicable for expression type

807600Jun 4 2007 — edited Jun 4 2007
p.s.v.main(String args[]){
 Basket<Fruit> b = new Basket<Fruit> ();
 b.setElement(new Apple());
 for(Object o: b) // compiler error. 
                            //foreach not applicable for expression type
  System.out.println(o); 
}
could you please explain why the for loop is causing error.

Thanks
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 2 2007
Added on Jun 4 2007
1 comment
220 views