java.lang.Object
ru.vyarus.dropwizard.guice.module.installer.util.InstanceUtils

public final class InstanceUtils extends Object
Class instance creation utility (to gather all instantiations in one place).
Since:
16.11.2023
  • Method Details

    • create

      public static <T> T create(Class<T> type)
      Create a new instance using no-args constructor.
      Type Parameters:
      T - instance type
      Parameters:
      type - class
      Returns:
      class instance
    • create

      public static <T> T create(Class<T> type, Class<?> param, Object arg)
      Shortcut for create(Class, Class[], Object...) for one constructor argument.
      Type Parameters:
      T - instance type
      Parameters:
      type - class
      param - constructor parameter type
      arg - parameter value
      Returns:
      object instance
    • create

      public static <T> T create(Class<T> type, Class<?>[] param, Object... args)
      Create a new instance using constructor with provided parameters and values.
      Type Parameters:
      T - instance type
      Parameters:
      type - class
      param - constructor parameter types
      args - constructor arguments
      Returns:
      object instance
    • createWithNulls

      public static <T> T createWithNulls(Class<T> type, Class<?>... param)
      Create new instance using constructor with provided params and nulls as values.
      Type Parameters:
      T - instance type
      Parameters:
      type - class
      param - constructor params
      Returns:
      object instance
    • createWithAnyConstructor

      public static <T> T createWithAnyConstructor(Class<T> type)
      For tests ONLY!

      Tries to find constructor with the smallest amount of arguments and use it with nulls to instantiate object.

      WARNING: primitive arguments are not supported!

      Type Parameters:
      T - target type
      Parameters:
      type - class
      Returns:
      class instance