zoukankan      html  css  js  c++  java
  • 通过反射获取列表属性里保存的对象类型

    假设有个对象里有一个list<Object> listProperty 属性,要获取Object的类型:

    Class<?> typeClass = field.getType();
    if (List.class.isAssignableFrom(typeClass)) {
          Type fieldType = field.getGenericType();
           if (fieldType instanceof ParameterizedType) {
                   ParameterizedType paramType = (ParameterizedType) fieldType;
                   Type[] genericTypes = paramType.getActualTypeArguments();
                   if (genericTypes != null && genericTypes.length > 0) {
                            if (genericTypes[0] instanceof Class<?>) {
                                  Class<?> subType = (Class<?>) genericTypes[0];
                            }
                   }
           }
    }
    

    其中subType就是Object的对象类型。

  • 相关阅读:
    EM算法
    最大熵模型中的对数似然函数的解释
    PySpark 自定义函数 UDF
    PySpark 自定义聚合函数 UDAF
    Numpy总结
    Examples
    Examples
    Examples
    Examples
    Examples
  • 原文地址:https://www.cnblogs.com/BensonHe/p/4401783.html
Copyright © 2011-2022 走看看