### Question:
GenericUtils { @SuppressWarnings("unchecked") public static <T> java.util.List<T> convert(java.util.List<?> list, Class<T> clzz) { for (Object o : list) { if (!clzz.isAssignableFrom(o.getClass()) ) { throw new RuntimeException("invalid list conversion, " + clzz.getName() + " list contains " + o.getClass()); } } return (List<T>) list; }  @SuppressWarnings("unchecked") static java.util.List<T> convert(java.util.List<?> list, Class<T> clzz);  }### Answer:
@Test public void goodConvert( ) { ArrayList<Object> al = new ArrayList<Object>( ); for (int i = 0; i < 5; i++) { al.add(Integer.valueOf(i)); } List<Integer> asIntArray = GenericUtils.convert(al, Integer.class); for (int i = 0; i < 5; i++) { assertTrue(asIntArray.get(i) == i); } }
@Test(expected = RuntimeException.class) public void badConvert( ) { ArrayList<Object> al = new ArrayList<Object>( ); for (int i = 0; i < 5; i++) { al.add(Integer.valueOf(i)); } List<String> asIntArray = GenericUtils.convert(al, String.class); System.out.println(asIntArray); }