TypeLiteral.java 文件源码

java
阅读 54 收藏 0 点赞 0 评论 0

项目:elasticsearch_my 作者:
/**
 * Returns the resolved generic parameter types of {@code methodOrConstructor}.
 *
 * @param methodOrConstructor a method or constructor defined by this or any supertype.
 * @since 2.0
 */
public List<TypeLiteral<?>> getParameterTypes(Member methodOrConstructor) {
    Type[] genericParameterTypes;

    if (methodOrConstructor instanceof Method) {
        Method method = (Method) methodOrConstructor;
        if (!method.getDeclaringClass().isAssignableFrom(rawType)) {
            throw new IllegalArgumentException(method + " is not defined by a supertype of " + type);
        }
        genericParameterTypes = method.getGenericParameterTypes();

    } else if (methodOrConstructor instanceof Constructor) {
        Constructor constructor = (Constructor) methodOrConstructor;
        if (!constructor.getDeclaringClass().isAssignableFrom(rawType)) {
            throw new IllegalArgumentException(constructor + " does not construct a supertype of " + type);
        }

        genericParameterTypes = constructor.getGenericParameterTypes();

    } else {
        throw new IllegalArgumentException("Not a method or a constructor: " + methodOrConstructor);
    }

    return resolveAll(genericParameterTypes);
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号