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:
@@ -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.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user