Types { public static Class<?> getRawType(Type type) { if (type instanceof Class<?>) { return (Class<?>) type; } if (type instanceof ParameterizedType) { Type rawType = ((ParameterizedType) type).getRawType(); if (rawType instanceof Class<?>) { return (Class<?>) rawType; } throw new IllegalStateException( format("getRawType of the parameterized type %s did not return a class, but %s", type, rawType)); } if (type instanceof GenericArrayType) { Type componentType = ((GenericArrayType) type).getGenericComponentType(); return Array.newInstance(getRawType(componentType), 0).getClass(); } throw new IllegalArgumentException( format("Unhandled type %s, unable to extract its raw type.", type)); }  static ParameterizedType newParameterizedType(final Class<?> rawType, final Type... arguments); static Class<?> getRawType(Type type); static boolean isAssignableFrom(Type t1, Type t2);  }
@Test public void getRawType_should_return_the_class_of_non_parametrized_types() { softly.assertThat(Types.getRawType(Integer.class)).isEqualTo(Integer.class); softly.assertThat(Types.getRawType(String.class)).isEqualTo(String.class); softly.assertThat(Types.getRawType(int.class)).isEqualTo(int.class); }
@Test public void getRawType_should_return_the_reified_class_of_parametrized_types() { softly.assertThat(Types.getRawType(new TypeReference<List<String>>() {}.getType())) .isEqualTo(List.class); softly.assertThat(Types.getRawType(new TypeReference<Map<String, Integer>>() {}.getType())) .isEqualTo(Map.class); }
@Test public void getRawType_should_return_the_class_of_array_types() throws NoSuchMethodException { softly.assertThat(Types.getRawType(new TypeReference<List<String>[]>() {}.getType())) .isEqualTo(List[].class); }