Why is an array not assignable to Iterable?

Arrays can implement interfaces (Cloneable and java.io.Serializable). So why not Iterable? I guess Iterable forces adding an iterator method, and arrays don’t implement methods. char[] doesn’t even override toString. Anyway, arrays of references should be considered less than ideal – use Lists. As dfa comments, Arrays.asList will do the conversion for you, explicitly.

(Having said that, you can call clone on arrays.)

Leave a Comment