Improve isNullOrEmpty() extensions
- Annotate with SinceKotlin("1.3") and InlineOnly
- Add contract linking the receiver and the returned value
- Unify wording in docs
- Add sample for Map.isNullOrEmpty
#KT-23279
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
package samples.collections
|
||||
|
||||
import samples.*
|
||||
import kotlin.test.*
|
||||
|
||||
|
||||
@RunWith(Enclosed::class)
|
||||
@@ -38,10 +39,10 @@ class Arrays {
|
||||
val nullArray: Array<Any>? = null
|
||||
assertTrue(nullArray.isNullOrEmpty())
|
||||
|
||||
val emptyArray = emptyArray<Any>()
|
||||
val emptyArray: Array<Any>? = emptyArray<Any>()
|
||||
assertTrue(emptyArray.isNullOrEmpty())
|
||||
|
||||
val array = arrayOf('a', 'b', 'c')
|
||||
val array: Array<Char>? = arrayOf('a', 'b', 'c')
|
||||
assertFalse(array.isNullOrEmpty())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -106,6 +106,18 @@ class Maps {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Sample
|
||||
fun mapIsNullOrEmpty() {
|
||||
val nullMap: Map<String, Any>? = null
|
||||
assertTrue(nullMap.isNullOrEmpty())
|
||||
|
||||
val emptyMap: Map<String, Any>? = emptyMap<String, Any>()
|
||||
assertTrue(emptyMap.isNullOrEmpty())
|
||||
|
||||
val map: Map<Char, Int>? = mapOf('a' to 1, 'b' to 2, 'c' to 3)
|
||||
assertFalse(map.isNullOrEmpty())
|
||||
}
|
||||
}
|
||||
|
||||
class Filtering {
|
||||
|
||||
Reference in New Issue
Block a user