private static Object getGenericType()

in src/main/java/org/apache/commons/pool3/impl/PoolImplUtils.java [79:108]


    private static <T> Object getGenericType(final Class<T> type, final Class<? extends T> clazz) {
        if (type == null || clazz == null) {
            // Error will be logged further up the call stack
            return null;
        }

        // Look to see if this class implements the generic interface
        final ParameterizedType pi = getParameterizedType(type, clazz);
        if (pi != null) {
            return getTypeParameter(clazz, pi.getActualTypeArguments()[0]);
        }

        // Interface not found on this class. Look at the superclass.
        @SuppressWarnings("unchecked")
        final Class<? extends T> superClass = (Class<? extends T>) clazz.getSuperclass();

        final Object result = getGenericType(type, superClass);
        if (result instanceof Class<?>) {
            // Superclass implements interface and defines explicit type for generic
            return result;
        }
        if (result instanceof Integer) {
            // Superclass implements interface and defines unknown type for generic
            // Map that unknown type to the generic types defined in this class
            final ParameterizedType superClassType = (ParameterizedType) clazz.getGenericSuperclass();
            return getTypeParameter(clazz, superClassType.getActualTypeArguments()[((Integer) result).intValue()]);
        }
        // Error will be logged further up the call stack
        return null;
    }