Generating remove() for Iterator using same mechanism.
This commit is contained in:
@@ -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"
|
||||
}
|
||||
Reference in New Issue
Block a user