Code example for Constructor

Methods: isAccessible, setAccessible

0
  } 
 
  private <T> ObjectConstructor<T> newDefaultConstructor(Class<? super T> rawType) {
    try { 
      final Constructor<? super T> constructor = rawType.getDeclaredConstructor();
      if (!constructor.isAccessible()) {
        constructor.setAccessible(true);
      } 
      return new ObjectConstructor<T>() { 
        @SuppressWarnings("unchecked") // T is the same raw type as is requested 
        public T construct() { 
          try { 
            Object[] args = null;
            return (T) constructor.newInstance(args);
          } catch (InstantiationException e) {
            // TODO: JsonParseException ? 
            throw new RuntimeException("Failed to invoke " + constructor + " with no args", e);
          } catch (InvocationTargetException e) {
            // TODO: don't wrap if cause is unchecked! 
            // TODO: JsonParseException ? 
            throw new RuntimeException("Failed to invoke " + constructor + " with no args",