Package org.instancio

Interface TypeToken<T>

  • Type Parameters:
    T - type being supplied.

    Required to be present, though not used directly.

    All Superinterfaces:
    Supplier<Type>, TypeTokenSupplier<T>

    public interface TypeToken<T>
    extends TypeTokenSupplier<T>
    A supplier that provides Type information. It can be used with generic classes in order to avoid "unchecked assignment" warnings.

    The following examples both create an instance of @{code Pair} class.

    
          // Generates an "unchecked assignment" warning
          // which can be suppressed with @SuppressWarnings("unchecked")
          Pair<Integer, String> pair = Instancio.of(Pair.class)
              .withTypeParameters(Integer.class, String.class)
              .create();
    
         // This usage avoids the warning
         Pair<Integer, String> pair = Instancio.of(new TypeToken<Pair<Integer, String>>() {}).create();
     
    Since:
    1.0.1
    • Method Detail

      • get

        default Type get()
        Returns the type to be created.
        Specified by:
        get in interface Supplier<T>
        Specified by:
        get in interface TypeTokenSupplier<T>
        Returns:
        type to create
        Since:
        1.0.1