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);
}
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);
}
It's a Java array, so we can do nothing about what it implements. Use .toList() to convert it to a list.
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)
}
Thank you! Sorry for my stupid question :)