public static Class < ? > getRawType ( Type type ) { if ( type instanceof Class ) { return ( Class < ? > ) type ; } else if ( type instanceof ParameterizedType ) { ParameterizedType actualType = ( ParameterizedType ) type ; return getRawType ( actualType . getRawType ( ) ) ; } else if ( type instanceof GenericArrayType ) { GenericArrayType genericArrayType = ( GenericArrayType ) type ; Object rawArrayType = Array . newInstance ( getRawType ( genericArrayType . getGenericComponentType ( ) ) , 0 ) ; return rawArrayType . getClass ( ) ; } else if ( type instanceof WildcardType ) { WildcardType castedType = ( WildcardType ) type ; return getRawType ( castedType . getUpperBounds ( ) [ 0 ] ) ; } else { throw new IllegalArgumentException ( "Type \'" + type + "\' is not a Class, " + "ParameterizedType, or GenericArrayType. Can't extract class." ) ; } }
This method returns the actual raw class associated with the specified type .