Provide a way to construct an empty typed array without init lambda.
This commit is contained in:
@@ -13,3 +13,7 @@ public inline fun <reified T> Array(size: Int, init: (Int) -> T): Array<T> {
|
||||
|
||||
return result as Array<T>
|
||||
}
|
||||
|
||||
// Returns an empty array of the specified type `T`.
|
||||
public inline fun <reified T> emptyArray(): Array<T> = arrayOfNulls<T>(0) as Array<T>
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ class ArraysTest {
|
||||
val arr1 = IntArray(0)
|
||||
assertEquals(-1, arr1.lastIndex)
|
||||
|
||||
val arr2 = Array<String>(0, { "$it" })
|
||||
val arr2 = emptyArray<String>()
|
||||
assertEquals(-1, arr2.lastIndex)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user