|Re: Builders for immutable collections (*List). [message #1804584 is a reply to message #1783177]
||Fri, 29 March 2019 03:45
| Donald Raab
Registered: March 2016
Sorry for the delay in responding to your question. There is no way to do this today, in terms of returning the ImmutableList interface after building up a MutableList without doing a final copy. However, you can use asUnmodifiable() as follows, which will simply adapt the MutableList with an unmodifiable adapter.
MutableList<Integer> integers = Lists.mutable.with(1, 2, 3, 4, 5).asUnmodifiable();
If you don't want to expose the mutating methods, you can additionally return ListIterable<Integer>.
ListIterable<Integer> integers = Lists.mutable.with(1, 2, 3, 4, 5).asUnmodifiable();
Hope that helps.
[Updated on: Fri, 29 March 2019 04:34]
Report message to a moderator
Powered by FUDForum
. Page generated in 0.01808 seconds