private static Class < ? > toClass ( Type o ) { if ( o instanceof GenericArrayType ) { Class clazz = Array . newInstance ( toClass ( ( ( GenericArrayType ) o ) . getGenericComponentType ( ) ) , 0 ) . getClass ( ) ; return clazz ; } return ( Class < ? > ) o ; }
Borrowed from java . lang . class