Introduce RandomAccess to JS.
Make EmptyList support RandomAccess. #KT-10794
This commit is contained in:
@@ -16,7 +16,7 @@ internal object EmptyIterator : ListIterator<Nothing> {
|
||||
override fun previous(): Nothing = throw NoSuchElementException()
|
||||
}
|
||||
|
||||
internal object EmptyList : List<Nothing>, Serializable {
|
||||
internal object EmptyList : List<Nothing>, Serializable, RandomAccess {
|
||||
override fun equals(other: Any?): Boolean = other is List<*> && other.isEmpty()
|
||||
override fun hashCode(): Int = 1
|
||||
override fun toString(): String = "[]"
|
||||
|
||||
@@ -854,4 +854,11 @@ class CollectionTest {
|
||||
// we need toString() inside pattern because of KT-8666
|
||||
assertEquals("[1, a, null, ${Long.MAX_VALUE.toString()}]", listOf(1, "a", null, Long.MAX_VALUE).toString())
|
||||
}
|
||||
|
||||
@test fun randomAccess() {
|
||||
assertTrue(arrayListOf(1) is RandomAccess, "ArrayList is RandomAccess")
|
||||
assertTrue(listOf(1, 2) is RandomAccess, "Default read-only list implementation is RandomAccess")
|
||||
assertTrue(listOf(1) is RandomAccess, "Default singleton list is RandomAccess")
|
||||
assertTrue(emptyList<Int>() is RandomAccess, "Empty list is RandomAccess")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user