Class InstanceUtils
- java.lang.Object
-
- ru.vyarus.dropwizard.guice.module.installer.util.InstanceUtils
-
public final class InstanceUtils extends java.lang.Object
Class instance creation utility (to gather all instantiations in one place).- Since:
- 16.11.2023
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> T
create(java.lang.Class<T> type)
Create a new instance using no-args constructor.static <T> T
create(java.lang.Class<T> type, java.lang.Class<?>[] param, java.lang.Object... args)
Create a new instance using constructor with provided parameters and values.static <T> T
create(java.lang.Class<T> type, java.lang.Class<?> param, java.lang.Object arg)
Shortcut forcreate(Class, Class[], Object...)
for one constructor argument.static <T> T
createWithAnyConstructor(java.lang.Class<T> type)
For tests ONLY!static <T> T
createWithNulls(java.lang.Class<T> type, java.lang.Class<?>... param)
Create new instance using constructor with provided params and nulls as values.
-
-
-
Method Detail
-
create
public static <T> T create(java.lang.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(java.lang.Class<T> type, java.lang.Class<?> param, java.lang.Object arg)
Shortcut forcreate(Class, Class[], Object...)
for one constructor argument.- Type Parameters:
T
- instance type- Parameters:
type
- classparam
- constructor parameter typearg
- parameter value- Returns:
- object instance
-
create
public static <T> T create(java.lang.Class<T> type, java.lang.Class<?>[] param, java.lang.Object... args)
Create a new instance using constructor with provided parameters and values.- Type Parameters:
T
- instance type- Parameters:
type
- classparam
- constructor parameter typesargs
- constructor arguments- Returns:
- object instance
-
createWithNulls
public static <T> T createWithNulls(java.lang.Class<T> type, java.lang.Class<?>... param)
Create new instance using constructor with provided params and nulls as values.- Type Parameters:
T
- instance type- Parameters:
type
- classparam
- constructor params- Returns:
- object instance
-
createWithAnyConstructor
public static <T> T createWithAnyConstructor(java.lang.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
-
-