TypedList implements List<Object> { public List<Object> subList(int fromIndex, int toIndex) { TypedList subList = new TypedList(this.type); subList.inner = inner.subList(fromIndex, toIndex); return subList; } TypedList(final ListType type);  TypedList(final ListType type, final Collection<? extends Object> collection); @SuppressWarnings("unchecked")  TypedList(final ListType type, final Object array); ListType getType(); Type getElementType(); void add(int index, Object element); boolean add(Object o); boolean addAll(Collection<? extends Object> c); boolean addAll(int index, Collection<? extends Object> c); void clear(); boolean contains(Object o); boolean containsAll(Collection<?> c); Object get(int index); int indexOf(Object o); boolean isEmpty(); Iterator<Object> iterator(); int lastIndexOf(Object o); ListIterator<Object> listIterator(); ListIterator<Object> listIterator(int index); Object remove(int index); boolean remove(Object o); boolean removeAll(Collection<?> c); boolean retainAll(Collection<?> c); Object set(int index, Object element); int size(); List<Object> subList(int fromIndex, int toIndex); Object[] toArray(); T[] toArray(T[] a); @Override int hashCode(); @Override boolean equals(Object obj);  }
@Test public void testSubList() throws Exception { String[] strings = new String[] { "a", "b", "c", null, "a", "b", "c", "d" }; List<Object> list = new TypedList(stringListType, strings); assertEquals(0, list.subList(4, 4).size()); int fromIndex = 1; int toIndex = 3; List<Object> subList = list.subList(fromIndex, toIndex); assertEquals(toIndex - fromIndex, subList.size()); for (int i = fromIndex; i < toIndex; i++) { assertEquals(strings[i], subList.get(i - fromIndex)); } subList.add("e"); assertEquals(3, subList.size()); assertEquals("b", subList.get(0)); assertEquals("c", subList.get(1)); assertEquals("e", subList.get(2)); assertEquals(9, list.size()); assertEquals("a", list.get(0)); assertEquals("b", list.get(1)); assertEquals("c", list.get(2)); assertEquals("e", list.get(3)); assertEquals(null, list.get(4)); assertEquals("a", list.get(5)); assertEquals("b", list.get(6)); assertEquals("c", list.get(7)); assertEquals("d", list.get(8)); subList.remove("b"); assertEquals(2, subList.size()); assertEquals("c", subList.get(0)); assertEquals("e", subList.get(1)); assertEquals(8, list.size()); assertEquals("a", list.get(0)); assertEquals("c", list.get(1)); assertEquals("e", list.get(2)); assertEquals(null, list.get(3)); assertEquals("a", list.get(4)); assertEquals("b", list.get(5)); assertEquals("c", list.get(6)); assertEquals("d", list.get(7)); subList.clear(); assertEquals(0, subList.size()); assertEquals(6, list.size()); assertEquals("a", list.get(0)); assertEquals(null, list.get(1)); assertEquals("a", list.get(2)); assertEquals("b", list.get(3)); assertEquals("c", list.get(4)); assertEquals("d", list.get(5)); }