Below code comes from Java 11, java.util.ImmutableCollections.java, line 783.
static final int EXPAND_FACTOR = 2;
MapN(Object... input) {
if ((input.length & 1) != 0) { // implicit nullcheck of input
throw new InternalError("length is odd");
}
size = input.length >> 1;
int len = EXPAND_FACTOR * input.length;
len = (len + 1) & ~1; // ensure table is even length
table = new Object[len];
Why the len
is twice input.length
? I think the table doesn't need to store elements more than input.length
.