mirror of
https://github.com/jlengrand/kotlin.git
synced 2026-05-13 08:31:31 +00:00
It's parameter is FQ-name of class (currently only from builtins) that added as supertype to annotated Java class. Parameters of annotated class used as non-flexible arguments of added supertype, that helps to propagate more precise types when using in Kotlin. Some standard JDK collections loaded as they annotated with PurelyImplements. See tests for clarification. Before: ArrayList<Int>.add(x: Int!) // possible to add null After: ArrayList<Int>.add(x: Int) // impossible to add null #KT-7628 Fixed #KT-7835 Fixed
55 lines
1.5 KiB
Kotlin
Vendored
55 lines
1.5 KiB
Kotlin
Vendored
// !DIAGNOSTICS: -UNUSED_VARIABLE
|
|
import java.util.*
|
|
|
|
fun bar(): String? = null
|
|
val nullableInt: Int? = null
|
|
|
|
fun hashMapTest() {
|
|
var x: HashMap<String?, Int> = HashMap<String?, Int>()
|
|
x.put(null, <!NULL_FOR_NONNULL_TYPE!>null<!>)
|
|
x.put("", <!NULL_FOR_NONNULL_TYPE!>null<!>)
|
|
x.put(bar(), 1)
|
|
x.put("", 1)
|
|
|
|
x[null] = 1
|
|
x[bar()] = 1
|
|
<!TYPE_INFERENCE_CONFLICTING_SUBSTITUTIONS!>x[""]<!> = nullableInt
|
|
x[""] = 1
|
|
|
|
val b1: MutableMap<String?, Int?> = <!TYPE_MISMATCH!>x<!>
|
|
val b2: MutableMap<String?, Int> = x
|
|
val b3: Map<String?, Int> = x
|
|
val b4: Map<String?, Int?> = x
|
|
val b5: Map<String, Int?> = <!TYPE_MISMATCH!>x<!>
|
|
|
|
val b6: Int = <!TYPE_MISMATCH!>x[""]<!>
|
|
val b7: Int = <!TYPE_MISMATCH!>x[null]<!>
|
|
val b8: Int = <!TYPE_MISMATCH!>x.get("")<!>
|
|
|
|
val b9: Int? = x.get("")
|
|
}
|
|
|
|
fun treeMapTest() {
|
|
var x: TreeMap<String?, Int> = TreeMap<String?, Int>()
|
|
x.put(null, <!NULL_FOR_NONNULL_TYPE!>null<!>)
|
|
x.put("", <!NULL_FOR_NONNULL_TYPE!>null<!>)
|
|
x.put(bar(), 1)
|
|
x.put("", 1)
|
|
|
|
x[null] = 1
|
|
x[bar()] = 1
|
|
<!TYPE_INFERENCE_CONFLICTING_SUBSTITUTIONS!>x[""]<!> = nullableInt
|
|
x[""] = 1
|
|
|
|
val b1: MutableMap<String?, Int?> = <!TYPE_MISMATCH!>x<!>
|
|
val b2: MutableMap<String?, Int> = x
|
|
val b3: Map<String?, Int> = x
|
|
val b4: Map<String?, Int?> = x
|
|
val b5: Map<String, Int?> = <!TYPE_MISMATCH!>x<!>
|
|
|
|
val b6: Int = <!TYPE_MISMATCH!>x[""]<!>
|
|
val b7: Int = <!TYPE_MISMATCH!>x.get("")<!>
|
|
|
|
val b8: Int? = x.get("")
|
|
}
|