mirror of
https://github.com/jlengrand/kotlin.git
synced 2026-05-16 15:53:55 +00:00
This change is to fill the gap between Kotlin Collection classes(immutable) and Java Collection classes(mutable), to avoid calling an unsupported operation like remove() on an immutable class in jvm.
32 lines
1.1 KiB
Kotlin
Vendored
32 lines
1.1 KiB
Kotlin
Vendored
// TARGET_BACKEND: JVM
|
|
|
|
interface Addable {
|
|
fun add(s: String): Boolean = true
|
|
}
|
|
|
|
class C : Addable, List<String> {
|
|
override val size: Int get() = null!!
|
|
override fun isEmpty(): Boolean = null!!
|
|
override fun contains(o: String): Boolean = null!!
|
|
override fun iterator(): Iterator<String> = null!!
|
|
override fun containsAll(c: Collection<String>): Boolean = null!!
|
|
override fun get(index: Int): String = null!!
|
|
override fun indexOf(o: String): Int = null!!
|
|
override fun lastIndexOf(o: String): Int = null!!
|
|
override fun listIterator(): ListIterator<String> = null!!
|
|
override fun listIterator(index: Int): ListIterator<String> = null!!
|
|
override fun subList(fromIndex: Int, toIndex: Int): List<String> = null!!
|
|
}
|
|
|
|
fun box(): String {
|
|
try {
|
|
val a = C()
|
|
if (!a.add("")) return "Fail 1"
|
|
if (!(a as Addable).add("")) return "Fail 2"
|
|
if (!(a as java.util.List<String>).add("")) return "Fail 3"
|
|
return "OK"
|
|
} catch (e: UnsupportedOperationException) {
|
|
return "Fail: no stub method should be generated"
|
|
}
|
|
}
|