Easy creation of ImmutableList
Summary: Per title. You don't want to have to create a separate list yourself that you then just wrap.
package com.facebook.common.internal;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
/**
@@ -25,4 +26,10 @@ public class ImmutableList<E> extends ArrayList<E> {
public static <E> ImmutableList<E> copyOf(List<E> list) {
return new ImmutableList<>(list);
}
+
+ public static <E> ImmutableList<E> of(E... elements) {
+ List<E> list = new ArrayList<>(elements.length);
+ Collections.addAll(list, elements);
+ return new ImmutableList<>(list);
+ }
}
