Creates a ConsList. It consists of an element pre-pended to another list. If the other list is mutable, creates an immutable copy.
(E first, List<? extends E> rest)
| 42 | * It consists of an element pre-pended to another list. |
| 43 | * If the other list is mutable, creates an immutable copy. */ |
| 44 | public static <E> List<E> of(E first, List<? extends E> rest) { |
| 45 | if (rest instanceof ConsList |
| 46 | || rest instanceof ImmutableList |
| 47 | && !rest.isEmpty()) { |
| 48 | //noinspection unchecked |
| 49 | return new ConsList<>(first, (List<E>) rest); |
| 50 | } else { |
| 51 | return ImmutableList.<E>builder().add(first).addAll(rest).build(); |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | private ConsList(E first, List<E> rest) { |
| 56 | this.first = first; |