當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。