### Question:
PropertyUtil { public static Class<?> getCollectionElementType(Type type) { if (! (type instanceof ParameterizedType)) { return Object.class; } ParameterizedType ptype = (ParameterizedType) type; Class<?> rawType = (Class<?>) ptype.getRawType(); try { if (Collection.class.isAssignableFrom(rawType)) { return TypeToken.of(type).resolveType(Collection.class.getMethod("add", Object.class).getGenericParameterTypes()[0]).getRawType(); } if (Map.class.isAssignableFrom(rawType)) { return TypeToken.of(type).resolveType(Map.class.getMethod("put", Object.class, Object.class).getGenericParameterTypes()[1]).getRawType(); } } catch (Exception e) { logger.warn("Failed while getting the collection element type", e); } return Object.class; } private  PropertyUtil(); static boolean isSimpleProperty(Class<?> clazz); static boolean isSimpleValueType(Class<?> clazz); static boolean isCollectionProperty(Type type, boolean includeMaps); static boolean isCollectionProperty(Class<?> clazz, boolean includeMaps); static boolean isMapProperty(Type type); static boolean isMapProperty(Class<?> clazz); static Class<?> getCollectionElementType(Type type); static Object getProperty(Object bean, String name); static void setProperty(Object bean, String name, Object value); static Method getReadMethod(Object bean, String name); static Boolean isPrimitiveOrWrapper(Class<?> clazz);  }### Answer:
@Test public void shouldGetCollectionType() throws Exception { assertEquals(PropertyUtil.getCollectionElementType(DummyClass.class.getField("stringList").getGenericType()), String.class); assertEquals(PropertyUtil.getCollectionElementType(DummyClass.class.getField("objectList").getGenericType()), DummyClass.class); assertEquals(PropertyUtil.getCollectionElementType(DummyClass.class.getField("anyList").getGenericType()), Object.class); }
@Test public void shouldGetCollectionTypeForMap() throws Exception { assertEquals(PropertyUtil.getCollectionElementType(DummyClass.class.getField("stringMap").getGenericType()), String.class); assertEquals(PropertyUtil.getCollectionElementType(DummyClass.class.getField("genericType").getGenericType()), Object.class); }