Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Iterable as a return type

Tags:

java

iterable

I'm having trouble understanding a method. I have methods that I need to fill out, but I don't really understand the first one. How can Iterable be a return type and how is it used ? An example would be great..

@Override
public Iterable<ClientInterface> getNeighbours() {

    return null;
}

@Override
public void addNeighbour(ClientInterface newNeighbour){
    //TODO Implement me!
}

@Override
public void removeNeighbour(String clientID) {
    //TODO Implement me!
}
like image 661
Tolga Tamer Avatar asked Apr 18 '14 21:04

Tolga Tamer


1 Answers

It looks like your class should have an implementation of Iterable<ClientInterface> as a class member, like ArrayList.

Let's use this as an example:

public class Bus {
   private ArrayList<Person> riders;
   ... //constructors and other methods

   public Iterable<Person> getRiders() {

     return riders;

   }
   ... //other methods
}
like image 107
Mike Avatar answered Oct 04 '22 09:10

Mike