File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes How to make my class iterable? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Reply locked New topic

How to make my class iterable?

Theodore David Williams
Ranch Hand

Joined: Dec 21, 2009
Posts: 102
Matthew Brown

Joined: Apr 06, 2010
Posts: 4343

You need to implement the Iterable<T> interface.

Edit...incidentally, you can get that by looking at the language specification:
14.14.2 The enhanced for statement
The enhanced for statement has the form:
for ( VariableModifiersopt Type Identifier: Expression) Statement
The Expression must either have type Iterable or else it must be of an array type, or a compile-time error occurs.
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 38033
Please read this. Closing thread.
jQuery in Action, 2nd edition
subject: How to make my class iterable?
Similar Threads
how to convert a .jsp to a .java/.class file
help: error: cannot find symbol
Anonymous Inner Class
When can a classes be declared private?
reflection - invoking Methods by Name!!!