Guava ImmutableList
has a number of overloaded methods of()
. As discussed in the context of this resolved issue , they exist to avoid the warnings that occur when mixing varargs with generics.
But in addition to this, the methods of parameters 0 and 1 rely on the implementation of a specialized list. It would seem that the same could be done for parameter methods 2.11, thereby reducing memory consumption by these lists - along the lines
final class ImmutableListWith2Elements<E> extends ImmutableList<E> { final E e1; final E e2; ...
Instead, they use an array-based implementation, which means storing an array object and an array reference in addition to content references. Can you help me understand the tradeoffs involved?
source share