• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Iterator problem

 
Vijay Chandran
Ranch Hand
Posts: 186
Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Dear friends,
This code gives a compiler error: Can only iterate over an array or an instance of java.lang.Iterable

Kindly provide me the explanation of this compiler error

Regards,
Vijay
 
Paul Michael
Ranch Hand
Posts: 697
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The enhanced for loop in Java 5 works with the new Iterable interface which encapsulates an Iterator.

In your example, you are returning an Iterator instead of an Iterable.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic