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


Java Config.NO_ARGTYPES属性代码示例

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


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

示例1: getInstance

public static <T> T getInstance(Class<?> cls, Class<T> type, Class<?>[] argTypes,
                   Object[] args) throws JPFException {
  Object o = null;
  Constructor<?> ctor = null;

  if (cls == null) {
    return null;
  }

  while (o == null) {
    try {
      ctor = cls.getConstructor(argTypes);
      o = ctor.newInstance(args);
    } catch (NoSuchMethodException nmx) {
       
      if ((argTypes.length > 1) || ((argTypes.length == 1) && (argTypes[0] != Config.class))) {
        // fallback 1: try a single Config param
        argTypes = Config.CONFIG_ARGTYPES;
        args = config.CONFIG_ARGS;
      } else if (argTypes.length > 0) {
        // fallback 2: try the default ctor
        argTypes = Config.NO_ARGTYPES;
        args = Config.NO_ARGS;

      } else {
        // Ok, there is no suitable ctor, bail out
        throw new JPFException("no suitable ctor found for the peer class " + cls.getName());
      }
    } catch (IllegalAccessException iacc) {
      throw new JPFException("ctor not accessible: "
          + config.getMethodSignature(ctor));
    } catch (IllegalArgumentException iarg) {
      throw new JPFException("illegal constructor arguments: "
          + config.getMethodSignature(ctor));
    } catch (InvocationTargetException ix) {
      Throwable tx = ix.getCause();
      throw new JPFException("exception " + tx + " occured in " 
          + config.getMethodSignature(ctor));
    } catch (InstantiationException ivt) {
      throw new JPFException("abstract class cannot be instantiated");
    } catch (ExceptionInInitializerError eie) {
      throw new JPFException("static initialization failed:\n>> "
          + eie.getException(), eie.getException());
    }
  }

  // check type
  if (!cls.isInstance(o)) {
    throw new JPFException("instance not of type: "
        + cls.getName());
  }

  return type.cast(o); // safe according to above
}
 
开发者ID:grzesuav,项目名称:gjpf-core,代码行数:54,代码来源:NativePeer.java


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