### Question:
HeterogeneousSet extends AbstractSet<E> { @SuppressWarnings("unchecked") public List<E> getObjectsAsList() { int size = 0; Collection<List<? extends E>> values = myClassToObjectMap.values(); for (List<? extends E> list : values) { size += list.size(); } Object[] arr = new Object[size]; int pos = 0; for (List<? extends E> list : values) { System.arraycopy(list.toArray(), 0, arr, pos, list.size()); pos += list.size(); } return (List<E>)Arrays.asList(arr); }  @Override synchronized boolean add(E e); @Override synchronized boolean addAll(Collection<? extends E> c); synchronized boolean addAll(Collection<? extends E> c, Comparator<E> comparator); @Override synchronized void clear(); @Override boolean contains(Object o); @SuppressWarnings("unchecked") List<E> getObjectsAsList(); List<T> getObjectsOfClass(Class<T> cl); @Override Iterator<E> iterator(); @Override synchronized boolean remove(Object obj); @Override synchronized boolean removeAll(Collection<?> c); @Override int size();  }### Answer:
@Test public void testGetObjectsAsList() { TypeA a1 = new TypeA(); TypeA a2 = new TypeA(); TypeB b1 = new TypeB(); TypeB b2 = new TypeB(); HeterogeneousSet<Object> set = new HeterogeneousSet<>(); set.addAll(Arrays.asList(a1, a2, b1, b2, a1, a2)); List<Object> list = set.getObjectsAsList(); Assert.assertEquals(4, list.size()); Assert.assertTrue(list.containsAll(set)); }