summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Winson <chiuwinson@google.com> 2021-01-11 17:06:18 -0800
committer Winson <chiuwinson@google.com> 2021-01-12 07:59:07 -0800
commit590e9ffb4cb6f1b065ef943030a01e11ddce6f66 (patch)
tree79ab36129b4d90c15d882a781df1652b056f927f
parent565151c5641e737674037237ccfbf556a95f1454 (diff)
Add SparseArray#set for Kotlin index= operator
Just an alias for put to allow `array[index] = value` syntax in Kotlin. Bug: 163565712 Test: manual, used in tests for separate feature Change-Id: Ie9e17b8f4d16a52f4dc213e1ada8d61fce9eedaf
-rw-r--r--core/api/current.txt1
-rw-r--r--core/java/android/util/SparseArray.java8
2 files changed, 9 insertions, 0 deletions
diff --git a/core/api/current.txt b/core/api/current.txt
index 99d8b51e185f..d3127fc41d48 100644
--- a/core/api/current.txt
+++ b/core/api/current.txt
@@ -45372,6 +45372,7 @@ package android.util {
method public void remove(int);
method public void removeAt(int);
method public void removeAtRange(int, int);
+ method public void set(int, E);
method public void setValueAt(int, E);
method public int size();
method public E valueAt(int);
diff --git a/core/java/android/util/SparseArray.java b/core/java/android/util/SparseArray.java
index dae760f989f6..86120d1e650c 100644
--- a/core/java/android/util/SparseArray.java
+++ b/core/java/android/util/SparseArray.java
@@ -241,6 +241,14 @@ public class SparseArray<E> implements Cloneable {
}
/**
+ * Alias for {@link #put(int, Object)} to support Kotlin [index]= operator.
+ * @see #put(int, Object)
+ */
+ public void set(int key, E value) {
+ put(key, value);
+ }
+
+ /**
* Adds a mapping from the specified key to the specified value,
* replacing the previous mapping from the specified key if there
* was one.