当前位置: 首页>>代码示例>>Java>>正文


Java Method.getGenericExceptionTypes方法代码示例

本文整理汇总了Java中java.lang.reflect.Method.getGenericExceptionTypes方法的典型用法代码示例。如果您正苦于以下问题:Java Method.getGenericExceptionTypes方法的具体用法?Java Method.getGenericExceptionTypes怎么用?Java Method.getGenericExceptionTypes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.lang.reflect.Method的用法示例。


在下文中一共展示了Method.getGenericExceptionTypes方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getExceptionTypes

import java.lang.reflect.Method; //导入方法依赖的package包/类
/**
 * Returns the resolved generic exception types thrown by {@code constructor}.
 *
 * @param methodOrConstructor a method or constructor defined by this or any supertype.
 * @since 2.0
 */
public List<TypeLiteral<?>> getExceptionTypes(Member methodOrConstructor) {
    Type[] genericExceptionTypes;

    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);
        }

        genericExceptionTypes = method.getGenericExceptionTypes();

    } 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);
        }
        genericExceptionTypes = constructor.getGenericExceptionTypes();

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

    return resolveAll(genericExceptionTypes);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:31,代码来源:TypeLiteral.java

示例2: getExceptionTypes

import java.lang.reflect.Method; //导入方法依赖的package包/类
/**
 * Returns the resolved generic exception types thrown by {@code constructor}.
 *
 * @param methodOrConstructor a method or constructor defined by this or any supertype.
 * @since 2.0
 */
public List<TypeLiteral<?>> getExceptionTypes(Member methodOrConstructor) {
  Type[] genericExceptionTypes;

  if (methodOrConstructor instanceof Method) {
    Method method = (Method) methodOrConstructor;
    checkArgument(method.getDeclaringClass().isAssignableFrom(rawType),
        "%s is not defined by a supertype of %s", method, type);
    genericExceptionTypes = method.getGenericExceptionTypes();

  } else if (methodOrConstructor instanceof Constructor) {
    Constructor<?> constructor = (Constructor<?>) methodOrConstructor;
    checkArgument(constructor.getDeclaringClass().isAssignableFrom(rawType),
        "%s does not construct a supertype of %s", constructor, type);
    genericExceptionTypes = constructor.getGenericExceptionTypes();

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

  return resolveAll(genericExceptionTypes);
}
 
开发者ID:maetrive,项目名称:businessworks,代码行数:28,代码来源:TypeLiteral.java


注:本文中的java.lang.reflect.Method.getGenericExceptionTypes方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。