Files
kotlin-fork/compiler/testData/diagnostics/tests/extensions/GenericIterator.kt
T
Mikhael Bogdanov d11311ec20 Test compilation fix
2013-12-02 18:30:42 +04:00

37 lines
701 B
Kotlin

import java.util.Enumeration
fun <T> java.util.Enumeration<T>.iterator() = object: Iterator<T> {
override fun hasNext(): Boolean = hasMoreElements()
override fun next() = nextElement()
}
trait MyIterator<T> {
fun hasNext() : Boolean
fun next() : T
}
fun <T : Any> T?.iterator() = object : MyIterator<T> {
var hasNext = this@iterator != null
private set
override fun hasNext() = hasNext
override fun next() : T {
if (hasNext) {
hasNext = false
return this@iterator!!
}
throw java.util.NoSuchElementException()
}
}
fun main(args : Array<String>) {
val i : Int? = 1
for (x in i) {
System.out.println(x)
}
}