ImmutableList extends AbstractList<E> implements Serializable { @Override public abstract ImmutableList<E> subList(int fromIndex, int toIndex); private  ImmutableList(); @SuppressWarnings("unchecked") @Nonnull static ImmutableList<E> copyOf(Collection<? extends E> original); static Collector<E, ?, ImmutableList<E>> collector(); @SuppressWarnings("unchecked") static ImmutableList<E> of(); static ImmutableList<E> of(E singleton); @Override abstract int indexOf(@Nullable Object object); @Override abstract int lastIndexOf(@Nullable Object object); @Override abstract ImmutableList<E> subList(int fromIndex, int toIndex);  }
@Test public void subListTest() { ImmutableList<Integer> list = ImmutableList.copyOf(Arrays.asList(1, 2, 3, 4, 5)); Assert.assertTrue(list.subList(2, 2) instanceof ImmutableList.EmptyList<?>); ImmutableList<Integer> singletonList = list.subList(2, 3); Assert.assertTrue(singletonList instanceof ImmutableList.SingletonList<?>); Assert.assertEquals(singletonList, Collections.singletonList(3)); ImmutableList<Integer> smallList = list.subList(2, 5); Assert.assertTrue(smallList instanceof ImmutableList.SubList<?>); Assert.assertEquals(smallList, Arrays.asList(3, 4, 5)); Assert.assertTrue(smallList.subList(1, 1) instanceof ImmutableList.EmptyList<?>); ImmutableList<Integer> singletonSublist = smallList.subList(1, 2); Assert.assertTrue(singletonSublist instanceof ImmutableList.SingletonList<?>); Assert.assertEquals(singletonSublist, Collections.singletonList(4)); ImmutableList<Integer> smallSublist = smallList.subList(1, 3); Assert.assertTrue(smallSublist instanceof ImmutableList.SubList<?>); Assert.assertEquals(smallSublist, Arrays.asList(4, 5)); }