|
Re: Builders for immutable collections (*List). [message #1804584 is a reply to message #1783177] |
Fri, 29 March 2019 03:45  |
Donald Raab Messages: 12 Registered: March 2016 |
Junior Member |
|
|
Hi Steve,
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.
Thanks,
Don
[Updated on: Fri, 29 March 2019 04:34] Report message to a moderator
|
|
|
Powered by
FUDForum. Page generated in 0.02128 seconds