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<Result> 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
This commit is contained in:
Steven Moreland
2018-01-05 09:41:10 -08:00
parent ae81e15c9c
commit 4bfa2ebb89

View File

@@ -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 <E> Inner object type.
*/
public static final class Mutable<E> {
public E value;
public Mutable() {
value = null;
}
public Mutable(E value) {
this.value = value;
}
}
/**
* Similar to Arrays.deepHashCode, but also take care of lists.
*/