我无法理解一种方法。我有需要填写的方法,但我不太了解第一个。 Iterable 如何成为返回类型以及如何使用它?一个例子会很棒..
@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!
}
最佳答案
看起来你的类应该有一个 Iterable<ClientInterface>
的实现作为类成员,如 ArrayList。
让我们以此为例:
public class Bus {
private ArrayList<Person> riders;
... //constructors and other methods
public Iterable<Person> getRiders() {
return riders;
}
... //other methods
}
关于java - 可迭代作为返回类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23162559/