The situation looks like this:
First class:
class Something {
List<Object> names;
public Something(){
this.names = new ArrayList<Object>();
}
}
Second class I tried do something like that and it is not working:
class Main {
public static void main(String[] args){
Something names = new Something();
...
for(Object name: names){
...
}
}
}
And it says that I can't iterate through "names" why? What am I doing wrong?
Somethingdoes not implementIterable<T>, so you cannot iterate over it directly; you must iterate over itsnamesfield:for(Object name : names.names)