https://kotlinlang.org logo
#announcements
Title
# announcements
v

ValV

06/21/2019, 1:26 AM
I'm writing a simple app in vim + gradle:
Copy code
class App {
  val listA = listOf(1, 8, 12, 17, 26, 31)
}

fun main(args: Array<String>) {
  val app = App()
  while (app.listA.hasNext()) {
    println(app.listA.next())
  }
}
But get this on
gradle run
Copy code
Unresolved reference: hasNext
Unresolved reference: next
Have I forgot something? Something in Gradle?
n

Nate

06/21/2019, 1:37 AM
yes… the rest of the question 😄
v

ValV

06/21/2019, 1:38 AM
Sorry, I'll explain
n

Nate

06/21/2019, 1:43 AM
Ah, you need to get an iterator first
In saying that, I’d use forEach rather:
app.listA.forEach { println(it) }
v

ValV

06/21/2019, 1:48 AM
Oops, my bad 🙂 Thanks
👍 1
One more question: how to reset iterator to the beginning?
n

Nate

06/21/2019, 2:18 AM
I don’t think you can. Just get a new one from the list
v

ValV

06/21/2019, 2:21 AM
Thanks, I have not found a way to do it myself, but I was not sure that I know everything 🙂
g

gildor

06/21/2019, 3:30 AM
what is your use case? Because sample above perfectly replaced with forEach
v

ValV

06/21/2019, 5:16 AM
It was test-case to reveal how iterators work
g

gildor

06/21/2019, 5:49 AM
I see
2 Views