Regarding the trait extend Doubt

scala

#1

Hi,
I had a doubt that for the below mentioned program the value of current is getting iterated to 1 each time, can you please clarify how it is happening, because i dont see any static in scala
Program: trait Iterator[A] {
def hasNext: Boolean
def next(): A
}
class IntIterator(to: Int) extends Iterator[Int] {
private var current = 0
override def hasNext: Boolean = current < to
override def next(): Int = {
if (hasNext) {
val t = current
current += 1
t
} else 0
}
}
val iterator = new IntIterator(10)
iterator.next()
iterator.next()

output:
0
1

For the second time it needs to be like 0 right, how the private value is 1.


#2

Hi,
can you please let me know whether someone looked into the issue that mentioned