TypeTokenUtils { public static TypeToken<?> extractElementTypeToken(TypeToken<?> typeToken) { if (typeToken.isSubtypeOf(Collection.class)) { List<TypeToken<?>> genericTypeTokens = TypeTokenUtils.extractGenericTypeTokens(typeToken); if (genericTypeTokens.size() == 0) { return TypeToken.of(Object.class); } else { return genericTypeTokens.get(0); } } else if (typeToken.isArray()) { return typeToken.getComponentType(); } else { throw new IllegalArgumentException("typeToken must be from List or array"); } }  static TypeToken<?> extractElementTypeToken(TypeToken<?> typeToken); static List<TypeToken<?>> extractGenericTypeTokens(TypeToken<?> typeToken);  }
@Test(expected = IllegalArgumentException.class) public void testRaiseException_extractElementTypeToken() { TypeTokenUtils.extractElementTypeToken(TypeToken.of(Integer.class)); }