I just noticed that ImmutableList.of(E[]) is deprecated in favor of ImmutableList.copyOf(), for the obvious reason that the list can't truly be made immutable if the raw array is used elsewhere.
What if you have a method that returns an array, and you know for a fact that the method doesn't hold onto a reference to the array, and your code doesn't hold onto a reference to the array other than passing it to ImmutableList.of()?
Should I...
- continue to use
ImmutableList.of(E[])(seems like a bad idea since the method will go away) - use
Collections.unmodifiableList(Arrays.asList()) - use
ImmutableList.copyOf()-- this seems like the best idea where performance/resource issues don't arise, otherwise the copy is unnecessary.