/** Creates a ConsList. * It consists of an element pre-pended to another list. * If the other list is mutable, creates an immutable copy. */ public static <E> List<E> of(E first, List<? extends E> rest) { if (rest instanceof ConsList || rest instanceof ImmutableList && !rest.isEmpty()) { //noinspection unchecked return new ConsList<>(first, (List<E>) rest); } else { return ImmutableList.<E>builder().add(first).addAll(rest).build(); } }
/** Creates a ConsList. * It consists of an element pre-pended to another list. * If the other list is mutable, creates an immutable copy. */ public static <E> List<E> of(E first, List<? extends E> rest) { if (rest instanceof ConsList || rest instanceof ImmutableList && !rest.isEmpty()) { //noinspection unchecked return new ConsList<>(first, (List<E>) rest); } else { return ImmutableList.<E>builder().add(first).addAll(rest).build(); } }