java - guava: best practices with ImmutableList.of(E[]) -
i noticed immutablelist.of(e[]) deprecated in favor of immutablelist.copyof(), obvious reason list can't made immutable if raw array used elsewhere.
what if have method returns array, , know fact method doesn't hold onto reference array, , code doesn't hold onto reference array other passing immutablelist.of()?
should i...
- continue use
immutablelist.of(e[])(seems bad idea since method go away) - use
collections.unmodifiablelist(arrays.aslist()) - use
immutablelist.copyof()-- seems best idea performance/resource issues don't arise, otherwise copy unnecessary.
immutablelist.of(e[]) not , has never stored array it's given directly (it wouldn't immutable if did, defeat point of class). deprecated naming reasons. if take @ implementation, is:
public static <e> immutablelist<e> of(e[] elements) { return copyof(elements); } so advice use immutablelist.copyof() in general. if know you're wrapping array internal use or such, feel free save copy , use arrays.aslist i'd prefer immutablelist api.
Comments
Post a Comment