Generating remove() for Iterator using same mechanism.

This commit is contained in:
Evgeny Gerashchenko
2013-09-24 17:14:17 +04:00
parent b4368ad578
commit 47b70427e1
7 changed files with 27 additions and 56 deletions
@@ -0,0 +1,13 @@
class MyIterator<T>(val v: T): Iterator<T> {
override fun next(): T = v
override fun hasNext(): Boolean = true
}
fun box(): String {
try {
(MyIterator<String>("") as MutableIterator<String>).remove()
throw AssertionError()
} catch (e: UnsupportedOperationException) {
return "OK"
}
}
@@ -1,5 +0,0 @@
public class removeInIterator {
public static void bar(java.util.Iterator<Integer> it) {
it.remove();
}
}
@@ -1,13 +0,0 @@
fun box() : String {
try {
removeInIterator.bar(object : Iterator<Int> {
public override fun hasNext(): Boolean = false
public override fun next(): Int = 1
})
}
catch (e: UnsupportedOperationException) {
if (e.getMessage() == "Mutating method called on a Kotlin Iterator")
return "OK"
}
return "fail"
}