Files
kotlin/compiler/testData/codegen/java8/box/mapRemove/readOnlyMap.kt
Denis Zharkov d259b91143 Add MutableMap.remove(K, V) as built-in declaration
Use PlatformDependent annotation to guarantee it's only be available for JDK8
Also adjust type-safe bridges and mutable collection stubs generation
2016-04-29 15:08:54 +03:00

46 lines
1.2 KiB
Kotlin
Vendored

// FULL_JDK
// WITH_RUNTIME
// FILE: A.java
public class A {
public static void foo(java.util.Map<String, String> x) {
x.remove("abc", "cde");
}
}
// FILE: main.kt
class ReadOnlyMap<K, V>(val x: K, val y: V) : Map<K, V> {
override val entries: Set<Map.Entry<K, V>>
get() = throw UnsupportedOperationException()
override val keys: Set<K>
get() = throw UnsupportedOperationException()
override val size: Int
get() = throw UnsupportedOperationException()
override val values: Collection<V>
get() = throw UnsupportedOperationException()
override fun containsKey(key: K) = key == x
override fun containsValue(value: V) = value == y
override fun get(key: K): V? = if (key == x) y else null
override fun isEmpty() = false
}
fun box(): String {
try {
A.foo(ReadOnlyMap("abc", "cde"))
return "fail 1"
} catch (e: UnsupportedOperationException) { }
try {
// Default Map 'remove' implenetation actually does remove iff entry exists
A.foo(ReadOnlyMap("abc", "123"))
return "fail 2"
} catch (e: UnsupportedOperationException) { }
return "OK"
}