From 4bfa2ebb89b909ac36094fd55080d749a996f5df Mon Sep 17 00:00:00 2001 From: Steven Moreland Date: Fri, 5 Jan 2018 09:41:10 -0800 Subject: Generic Mutable class for HIDL code. In general, using Mutable inside of structures or as API arguments is a code smell. However, it is the most syntactically clean way of fetching something out of a lambda or inner class. Using this, one can do: Mutable res = new Mutable<>(); hidlObject.foo((...) -> { res.value = ...; }); There is an alternative: Result a[] = new Result[1]; hidlObject.foo((...) -> { a[0] = ...; }); However, this alternative syntax is relatively messy. Bug: N/A Test: boot, use w/ wifi Change-Id: Ibff13c653cc17bd25ddbb0534ba21ef485bff7aa --- core/java/android/os/HidlSupport.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'core/java/android') diff --git a/core/java/android/os/HidlSupport.java b/core/java/android/os/HidlSupport.java index a080c8dcbcc5..4d7d9319c94e 100644 --- a/core/java/android/os/HidlSupport.java +++ b/core/java/android/os/HidlSupport.java @@ -85,6 +85,25 @@ public class HidlSupport { return lft.equals(rgt); } + /** + * Class which can be used to fetch an object out of a lambda. Fetching an object + * out of a local scope with HIDL is a common operation (although usually it can + * and should be avoided). + * + * @param Inner object type. + */ + public static final class Mutable { + public E value; + + public Mutable() { + value = null; + } + + public Mutable(E value) { + this.value = value; + } + } + /** * Similar to Arrays.deepHashCode, but also take care of lists. */ -- cgit v1.2.3