Why jet.Array not implements jet.Iterable?


#1

Why jet.Array not implements jet.Iterable?

For example, i’m cannot:

fun doSomething<T>(ts: Iterable<T>) {
  for (i in ts) {
  //bla bla bla
  }
}

fun test() {
  val a:Array<Int> = Vector<Int>().toArray();
  doSomething(a);
}


#2

It's a Java array, so we can do nothing about what it implements. Use .toList() to convert it to a list.


#3

Or use Iterator<T> instead of Iterable<T>

fun doSomething<T>(ts: Iterator<T>) {   for (i in ts) {   //bla bla bla   } }

fun test() {
  val a = array(1,2,3).iterator()
  doSomething(a)
  val b = arrayList(1,2,3).iterator()
  doSomething(b)
}


#4

Thank you! Sorry for my stupid question :)