TypedList implements List<Object> { public void add(int index, Object element) { inner.add(index, convertToTypedObject(element)); } 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 testAdd() throws Exception { List<Object> list = new TypedList(stringListType); String a = "a"; assertTrue(list.add(a)); assertEquals(1, list.size()); assertEquals(a, list.get(0)); String b = "b"; assertTrue(list.add(b)); assertEquals(2, list.size()); assertEquals(a, list.get(0)); assertEquals(b, list.get(1)); try { list.add(1); fail(); } catch (UnassignableValueException e) { } String c = "c"; list.add(1, c); assertEquals(3, list.size()); assertEquals(a, list.get(0)); assertEquals(c, list.get(1)); assertEquals(b, list.get(2)); String d = "d"; try { list.add(-1, d); fail(); } catch (IndexOutOfBoundsException e) { } try { list.add(list.size() + 1, d); fail(); } catch (IndexOutOfBoundsException e) { } }