GenericType { private static Class getClass(Type type) { if (type instanceof Class) { return (Class) type; } else if (type instanceof ParameterizedType) { ParameterizedType parameterizedType = (ParameterizedType) type; if (parameterizedType.getRawType() instanceof Class) { return (Class) parameterizedType.getRawType(); } } else if (type instanceof GenericArrayType) { GenericArrayType array = (GenericArrayType) type; final Class<?> componentRawType = getClass(array.getGenericComponentType()); return getArrayClass(componentRawType); } throw new IllegalArgumentException("Type parameter " + type.toString() + " not a class or " + "parameterized type whose raw type is a class"); } protected  GenericType();  GenericType(Type genericType); static GenericType forInstance(final Object instance); final Type getType(); final Class<?> getRawType(); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString();  }
@Test(expected = IllegalArgumentException.class) public void testInvalidGenericType() throws NoSuchMethodException { ArrayList<String> al = new ArrayList<String>(); Method addMethod = al.getClass().getMethod("add", Object.class); final Type type = addMethod.getGenericParameterTypes()[0]; new GenericType(type); }