• getGenericClass


    import java.lang.reflect.ParameterizedType;
    import java.lang.reflect.Type;

    public class GenericsUtils {
    /**
    * Locates the first generic declaration on a class.
    *
    * @param clazz The class to introspect
    * @return the first generic declaration, or <code>null</code> if cannot be determined
    */
    public static Class<?> getGenericClass(Class<?> clazz) {
    return getGenericClass(clazz, 0);
    }

    public static Class<?> getGenericClass(Class<?> clazz, int index) {
    Type genType = clazz.getGenericSuperclass();

    if (genType instanceof ParameterizedType) {
    Type[] params = ((ParameterizedType) genType).getActualTypeArguments();

    if ((params != null) && (params.length >= (index - 1))) {
    return (Class<?>) params[index];
    }
    }
    return null;
    }
    }



  • 相关阅读:
    023 AQS--JUC的核心
    022 Future接口
    021 Callable接口
    020 线程的综合考虑
    019 线程协作
    命令,lldb,llvm,gdb,gcc,
    @class,import,
    arc,自动引用计数,
    写在哪里,
    40岁生日,
  • 原文地址:https://www.cnblogs.com/jifsu/p/2199622.html
Copyright © 2020-2023  润新知