Package org.instancio

Interface InstancioOfClassApi<T>

Type Parameters:
T - type to create
All Superinterfaces:
InstancioApi<T>
All Known Implementing Classes:
InstancioOfClassApiImpl, InstancioOfCollectionApiImpl, InstancioOfMapApiImpl

public interface InstancioOfClassApi<T> extends InstancioApi<T>
Instancio API for defining type parameters for generic classes.
Since:
1.0.1
  • Method Details

    • withTypeParameters

      InstancioApi<T> withTypeParameters(Class<?>... types)
      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: