code: static <T> T newInstance(final Class<?> clazz, final Class<?>[] argumentTypes, final Object[] arguments,
          final Class<T> expectedType) {
          // Precondition checks
          if (clazz == null) {
              throw new IllegalArgumentException("Class must be specified");
          }
          if (argumentTypes == null) {
              throw new IllegalArgumentException("ArgumentTypes must be specified. Use empty array if no arguments");
          }
          if (arguments == null) {
              throw new IllegalArgumentException("Arguments must be specified. Use empty array if no arguments");
          }
          if (expectedType == null) {
              throw new IllegalArgumentException("Expected type must be specified");
          }
  
          // Get the ctor
          final Constructor<?> constructor;
          try {
              constructor = getConstructor(clazz, argumentTypes);
          } catch (final NoSuchMethodException e) {
              throw new RuntimeException("Could not create new instance of " + clazz + " using ctor argument types "
                  + Arrays.asList(argumentTypes), e);
          }
  
          // Create the instance
          final Object obj;
          try {
              obj = constructor.newInstance(arguments);
          } catch (final Exception e) {
              throw new RuntimeException("Could not create a new instance of " + clazz + " using arguments "
                  + Arrays.asList(arguments), e);
          }
  
          // Cast
          try {
              return expectedType.cast(obj);
          } catch (final ClassCastException cce) {
              // Reconstruct so we get some useful information
              throw new ClassCastException("Incorrect expected type, " + expectedType.getName() + ", defined for "
                  + obj.getClass().getName());
          }
      }
docs: Creates a new instance of the specified {@link Class} using the specified construction arguments. Casts and
  returns as the specified expected type
  
  @param <T>
  @param clazz
  @param argumentTypes
  @param arguments
  @param expectedType
  @return