ReflectUtils.java 文件源码

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

项目:dubbox-hystrix 作者:
public static Constructor<?> findConstructor(Class<?> clazz, Class<?> paramType) throws NoSuchMethodException {
    Constructor<?> targetConstructor;
try {
    targetConstructor = clazz.getConstructor(new Class<?>[] {paramType});
} catch (NoSuchMethodException e) {
    targetConstructor = null;
    Constructor<?>[] constructors = clazz.getConstructors();
    for (Constructor<?> constructor : constructors) {
        if (Modifier.isPublic(constructor.getModifiers()) 
                && constructor.getParameterTypes().length == 1
                && constructor.getParameterTypes()[0].isAssignableFrom(paramType)) {
            targetConstructor = constructor;
            break;
        }
    }
    if (targetConstructor == null) {
        throw e;
    }
}
return targetConstructor;
  }
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号