Beispiel #1
0
 @Override
 public <T> T defaultInstanceFor(Class<T> c)
     throws NoSuchMethodException, InstantiationException, IllegalAccessException,
         InvocationTargetException {
   final Object cached = cachedDefCtors.get(c);
   if (cached != null) {
     if (cached.getClass() == Constructor.class) {
       return ((Constructor<T>) cached).newInstance();
     }
     if (cached.getClass() == NoSuchMethodException.class) {
       throw (NoSuchMethodException) cached;
     }
     if (cached.getClass() == InstantiationException.class) {
       throw (InstantiationException) cached;
     }
     if (cached.getClass() == InvocationTargetException.class) {
       throw (InvocationTargetException) cached;
     }
     if (cached.getClass() == IllegalAccessException.class) {
       throw (IllegalAccessException) cached;
     }
   }
   try {
     final Constructor<T> ctor = ReflectionUtil.defaultConstructor(c);
     T ret = ctor.newInstance();
     cachedDefCtors.putIfAbsent(c, ctor);
     return ret;
   } catch (NoSuchMethodException
       | InstantiationException
       | InvocationTargetException
       | IllegalAccessException noDefCtorX) {
     cachedDefCtors.putIfAbsent(c, noDefCtorX);
     throw noDefCtorX;
   }
 }