private static void printIterable(Iterable iterable) {
// ERROR: "Type mismatch: cannot convert from element type Object to Iterable"
for (Iterable i : iterable) {
System.out.println(i);
}
}
What the compiler is talking about? Its an Iterable, not an Object.
You try to do something for each
Iterableinside theiterable. This would only make sense ifiterablewas anIterable<? extends Iterable>(i.e. it would iterate over yet otherIterableobjects).But since you didn’t specify a type argument for the argument, you only know that it will iterate over some kind of object (i.e. the base type
Objectis applicable).You should try this:
When read out loud it read as “For each
Objectoiniterable, printo“. ReplacingObjectin that sentence withIterableshould illustrate what the problem was.