Package org.instancio.internal
Class OfClassApiImpl<T>
java.lang.Object
org.instancio.internal.ApiImpl<T>
org.instancio.internal.OfClassApiImpl<T>
- All Implemented Interfaces:
InstancioApi<T>
,InstancioOfClassApi<T>
- Direct Known Subclasses:
OfCollectionApiImpl
,OfMapApiImpl
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionwithTypeParameters
(Class<?>... type) Method for supplying type parameters for generic classes.Methods inherited from class org.instancio.internal.ApiImpl
addTypeParameters, asResult, create, generate, generate, ignore, lenient, onComplete, set, stream, subtype, supply, supply, toModel, withMaxDepth, withNullable, withSeed, withSettings
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.instancio.InstancioApi
asResult, create, generate, generate, ignore, lenient, onComplete, set, stream, subtype, supply, supply, toModel, withMaxDepth, withNullable, withSeed, withSettings
-
Constructor Details
-
OfClassApiImpl
-
-
Method Details
-
withTypeParameters
Description copied from interface:InstancioOfClassApi
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>>() {});
- Specified by:
withTypeParameters
in interfaceInstancioOfClassApi<T>
- Parameters:
type
- one or more type arguments- Returns:
- API builder reference
- See Also:
-