I need to return/update a boolean while returning a list of stuff from a method. Java can’t return tuples and I didn’t want to make a separate class for this, so figured I would pass the bool as an out param. That’s what our C++ client does, passes bool by reference. That would work for a normal class since java sort of has pass-by-ref for objects (see Is Java "pass-by-reference" or "pass-by-value"? for a good discussion of this). But the “Wrapper” classes like Boolean store their primitive value as immutable, so it can’t be updated in this way.
Using a boolean array (with one entry) seems hokey but is perhaps the simplest thing that works. Alternatively, could return the boolean and pass the created list back as an out param rather than as the return [but then the java client deviates from the C++, and it’s best if they keep mostly the same approach- FYI need this in C# too.]
As you say, The Boolen wrapper class is immutable, so you cannot use it to receive your output variable.
Passing in a new list to receive the list result and returning the boolean would sound most natural to me, but you have a good reason; keeping the interface roughly the same over multiple implementations.
You could solve this problem by creating your own mutable Boolean and passing a reference to it, something like:
and use it like: