Package org.instancio
Interface InstancioOfClassApi<T>
- Type Parameters:
T
- type to create
- All Superinterfaces:
InstancioApi<T>
,InstancioOperations<T>
,LenientMode<T>
,VerboseMode<T>
Instancio API for defining type parameters for generic classes.
- Since:
- 1.0.1
-
Method Summary
Modifier and TypeMethodDescriptionwithTypeParameters
(Class<?>... types) Method for supplying type parameters for generic classes.Methods inherited from interface org.instancio.InstancioApi
asResult, assign, create, generate, generate, ignore, lenient, onComplete, set, setModel, stream, subtype, supply, supply, toModel, verbose, withMaxDepth, withNullable, withSeed, withSetting, withSettings
-
Method Details
-
withTypeParameters
Method for supplying type parameters for generic classes.Example:
List<Address> addresses = Instancio.of(List.class) .withTypeParameters(Address.class) .create();
This method can be used when the type parameters need to be supplied dynamically at runtime, however it also has a couple of limitations:
- its usage produces an unchecked assignment warning
- it cannot be used for nested generics, such as
Map<String, List<Integer>>
The recommended approach for instantiating generic classes is using
TypeTokens
:List<Address> addresses = Instancio.create(new TypeToken<List<Address>>() {});
- Parameters:
types
- one or more type arguments- Returns:
- API builder reference
- Since:
- 1.0.1
- See Also:
-