### Question:
Reflection { public static Class<?> getClass(Type type) { Class<?> clazz; if (type instanceof Class) { clazz = ((Class<?>)type); } else if (type instanceof ParameterizedType) { clazz = (Class<?>)((ParameterizedType)type).getRawType(); } else if (type == null) { throw new IllegalArgumentException("type must not be null"); } else { throw new IllegalArgumentException(String.format( "%s is not a class or parameterizedType", type)); } return clazz; } private  Reflection(); static Type resultType(Type declaringType, Type type); static Type variableType(ParameterizedType type, TypeVariable<?> variable); static Class<?> getClass(Type type); static boolean isGetter(Method method); static boolean isListIndex(Method method);  }### Answer:
@Test public void classForType() throws Exception { assertEquals(HashMap.class, Reflection.getClass(new Foo().getClass() .getGenericSuperclass())); Method method = Foo.class.getMethod("put", Object.class, Object.class); try { Reflection.getClass((TypeVariable<?>) method .getGenericParameterTypes()[0]); fail(); } catch (IllegalArgumentException expected) { } }